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?

ABC448をPythonで

0
Posted at

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

A問題

問題文通りシミュレーション

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

for a_i in a:
    if a_i < x:
        print(1)
        x = a_i
    else:
        print(0)

B問題

順番に使えるだけ使う

B
n, m = map(int, input().split())
c = list(map(int, input().split()))
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    use = min(c[a - 1], b)
    ans += use
    c[a - 1] -= use

print(ans)

C問題

SortedListを使って問題文通りのシミュレーションをする

C
from sortedcontainers import SortedList


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

s = SortedList(a)
for _ in range(q):
    k = int(input())
    b = list(map(lambda x:int(x) - 1, input().split()))
    for b_i in b:
        s.discard(a[b_i])
    print(s[0])
    for b_i in b:
        s.add(a[b_i])

D問題

dfsで上から確認

D
import sys;sys.setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int, input().split()))
edge = [list() for _ in range(n)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    edge[u - 1].append(v - 1)
    edge[v - 1].append(u - 1)

check = [False] * n
d = dict()
ans = [False] * n

def dfs(now, flg):
    global check, d, ans
    if a[now] not in d:
        d[a[now]] = 0
    if flg or d[a[now]] > 0:
        ans[now] = True
        flg = True
    d[a[now]] += 1
    check[now] = True
    for to in edge[now]:
        if check[to]:
            continue
        dfs(to, flg)
    d[a[now]] -= 1

dfs(0, False)

for ans_i in ans:
    print("Yes" if ans_i else "No")
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?