1
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?

ABC419をPythonで(A~D)

Posted at

AtCoder Beginner Contest 419の解答等の速報的まとめ

A問題

対応を辞書に入れて置き、なければUnknownを返す

A
d = {"red":"SSS", "blue":"FFF", "green":"MMM"}
s = input()
print("Unknown" if s not in d else d[s])

B問題

クエリ数が少ないので2が来た時に毎回ソートして最小値を取ればいい
配列を降順にすれば pop() で取れる

B
lst = list()
for _ in range(int(input())):
    com = list(map(int, input().split()))
    if com[0] == 1:
        lst.append(com[1])
    else:
        lst.sort(reverse=True)
        ans = lst.pop()
        print(ans)

C問題

縦方向か横方向で一番遠い組の距離の半分(端数切り上げ)が答え
なぜなら、近いほうは斜めに移動すれば遠いほうが揃う前に揃えられる

C
n = int(input())

r_min, r_max, c_min, c_max = 10 ** 10, 0, 10 ** 10, 0
for _ in range(n):
    r_i, c_i = map(int, input().split())
    r_min = min(r_min, r_i)
    r_max = max(r_max, r_i)
    c_min = min(c_min, c_i)
    c_max = max(c_max, c_i)

dist = max(r_max - r_min, c_max - c_min)

print((dist + 1) // 2)

D問題

変更回数を累積和で記録して、奇数回変更していたらTを採用する

D
n, m = map(int, input().split())
s = input()
t = input()

lst = [0] * (n + 10)
for _ in range(m):
    l_i, r_i = map(int, input().split())
    lst[l_i - 1] += 1
    lst[r_i] -= 1

for i in range(n):
    lst[i + 1] += lst[i]

ans = list()
for i in range(n):
    if lst[i] % 2 == 0:
        ans.append(s[i])
    else:
        ans.append(t[i])

print("".join(ans))
1
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
1
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?