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?

ABC402の記録

Last updated at Posted at 2025-04-28

はじめに

今回は不参加でした。あとから解いた。

成績:不参加

A

pythonには大文字かどうかを判断する関数があるのでそれを使う。

A
s = input()
ans = []
for i in range(len(s)):
    if s[i].isupper():
        ans.append(s[i])
print("".join(ans))

B

queueを使えばappendとpopleftで言われた通り対応可能。

B
from collections import deque
q = int(input())
row = deque([])
for _ in range(q):
    query = input()
    if query[0] == '1':
        row.append(int(query[1:]))
    else:
        v = row.popleft()
        print(v)

C

食材ごとにどの料理に使われているかをまとめておく。
最終日にはどの料理も食べられるので、その状態から一日ずつ食材を禁止していき、食べられなくなった料理をsetに入れていく。
で、mからその時点でのsetの要素数を引いた値を毎回出力する。
Kの合計が3x10^5以下なのでまあ間に合うという計算。

C
sys.stdin = io.StringIO(_INPUT)
#実際の提出はこの下
n,m = map(int,input().split())
#まず各料理に使われる食材の数と種類をまとめておく
dish = []
for _ in range(m):
    dish.append(list(map(int,input().split())))
#print(dish)

#次に食材ごとに使われている料理をまとめる
source = [[] for _ in range(n)]
for i in range(m):
    for j in range(dish[i][0]):
        source[dish[i][j+1]-1].append(i+1)
#print(source)

#最終日には全部食えるのでそこからさかのぼって減らしていく
eat = list(map(int,input().split()))
eat = eat[::-1]
noteat = set()
ans = [m]
for i in range(n-1):
    for j in source[eat[i]-1]:
        noteat.add(j)
    ans.append(m-len(noteat))
for a in ans[::-1]:
    print(a)

D

並行にならない限り交わるが、ほとんどの直線は交わるのでm(m-1)/2から交わるものを引くと考える。で、平行になるものは(A+B)%nが等しくなるらしい。どういう原理かはわからないが……

D
n,m = map(int,input().split())
lines = [0 for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    lines[(a+b)%n] += 1
ans = m * (m - 1) // 2
for i in range(n):
    if lines[i] >= 2:
        ans -= lines[i] * (lines[i] - 1) // 2
print(ans)

D問題が考察系だったので実際に参加していたらこれを解けたかどうかは怪しいところ……Cもやや難しいやり方をしてしまった気がする。

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?