0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC480のPython解答(A~D)

0
Posted at

AtCoder Talent Quest 〜 今から28卒には脱出してもらいます〜予選 #2(AtCoder Beginner Contest 480)の解答等の速報的まとめ

A問題

対角の位置にあったらNo

A
s = [input(), input()]

lst = [("A", "D"), ("D", "A")]

if (s[0][0], s[1][1]) in lst or (s[1][0], s[0][1]) in lst:
    print("No")
else:
    print("Yes")

B問題

全部確認

B
def diff_count(a, b):
    res = 0
    if len(a) != len(b):
        return 1000
    for a_i, b_i in zip(a, b):
        if a_i != b_i:
            res += 1
    return res


n, m = map(int, input().split())
s = [input() for _ in range(n)]

vote = [0] * n
for _ in range(m):
    t_i = input()
    same_ind = -1
    like_ind = list()
    for i, s_i in enumerate(s):
        diff = diff_count(s_i, t_i)
        if diff == 0:
            same_ind = i
        elif diff == 1:
            like_ind.append(i)
    if same_ind >= 0:
        vote[same_ind] += 1
    elif len(like_ind) == 1:
        vote[like_ind[0]] += 1

for v_i in vote:
    print(v_i)

C問題

止まったタイミングから次に押されるまでの間に押さなければならない回数を逐次計算

C
n, k ,t = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0
last_time = 0

for a_i in a:
    if t <= a_i:
        break
    if last_time < a_i:
        ans += (a_i - last_time + k - 1) // k
    last_time = max(last_time, a_i + k)

if last_time < t:
    ans += (t - last_time + k - 1) // k
print(ans)

D問題

最初から特定の場所までの総和を求める関数をつくる。

関数は累積和とそれの累積和からいい感じにできる

D
from bisect import bisect

n, q = map(int, input().split())
a = list(map(int, input().split()))

accu = [0]  # 0~iまでの和
for a_i in a:
    accu.append(accu[-1] + a_i)

b = [0]  # 問題文のbの1~n回目の操作後の全体の和
b_ind = [0]
i = 1
for acc_i in accu[1:]:
    b.append(b[-1] + acc_i)
    b_ind.append(b_ind[-1] + i)
    i += 1

def calc(x):
    if x <= 0:
        return 0

    i = bisect(b_ind, x) - 1
    res = b[i] + accu[x - b_ind[i]]

    return res

for _ in range(q):
    l_i, r_i = map(int, input().split())
    print(calc(r_i) - calc(l_i - 1))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?