2
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をPythonで(A~D)

Posted at

東京海上日動プログラミングコンテスト2025(AtCoder Beginner Contest 402)の解答等の速報的まとめ

A問題

大文字のものを選ぶだけ

A
s = input()
ans = list()

for s_i in s:
    if s_i.isupper():
        ans.append(s_i)

print(*ans, sep="")

B問題

dequeを使う

B
from collections import deque

q = deque()

for _ in range(int(input())):
    com = list(map(int, input().split()))
    if com[0] == 1:
        q.append(com[1])
    else:
        q_i = q.popleft()
        print(q_i)

C問題

$i$回目にそのメニュー内の食べ物がいくつダメかわかるようにして、それが0になったとき食べられるカウントを増やす

C
n, m = map(int, input().split())
menu = list()
ng_food = list()
food_list = [list() for _ in range(n + 1)]
ans = 0
for i in range(m):
    k, *arg = list(map(int, input().split()))
    menu.append(arg)
    ng_food.append(k)
    for a_i in arg:
        food_list[a_i].append(i)

for b_i in map(int, input().split()):
    for f_i in food_list[b_i]:
        ng_food[f_i] -= 1
        if ng_food[f_i] == 0:
            ans += 1
    print(ans)

D問題

交差しないものを数える
交差しない=傾きが等しい なので基準となる傾きを点1を通るものにして
それらがいくつあるか求める

D
def calc(a, b):
    while True:
        if a < b and (a == 1 or (a, b) == (2, n)):
            break
        elif a > b:
            a, b = b, a
        else:
            diff = min(a - 1, n - b)
            if diff == 0: # b == n
                a, b = 1, a - 1
            else:
                a -= diff
                b += diff

    return a, b


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

d = dict()
ans = m * (m - 1) // 2
for a_i, b_i in points:
    x, y = calc(a_i, b_i)
    if (x, y) not in d:
        d[(x, y)] = 0
    ans -= d[(x, y)]
    d[(x, y)] += 1

print(ans)
2
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
2
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?