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?

ABC388をPythonで(A~E)

Posted at

HHKBプログラミングコンテスト2025(AtCoder Beginner Contest 388)の解答等の速報的まとめ

A問題

問題文のまま

A
print(input()[0]+"UPC")

B問題

全部通り長さを調べる

B
n, d = map(int, input().split())
snake = [list(map(int, input().split())) for _ in range(n)]

for i in range(1, d + 1):
    ans = 0
    for t_i, l_i in snake:
        ans = max(ans, t_i * (l_i + i))

    print(ans)

C問題

尺取り法で各餅の2倍以上ある餅の数を数える

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

ans = 0
right = 0
for a_i in a:
    while right < n and a_i * 2 > a[right]:
        right += 1
    ans += n - right

print(ans)

D問題

石の個数は成人になったとき1度だけ増える。
渡せる宇宙人の人数は成人になった瞬間に確定するので、imos法を利用して石を渡す相手を管理する。

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

diff = [0] * (n + 10)
for i, a_i in enumerate(a):
    present = min(a_i, n - i - 1)
    a[i] -= present
    diff[i + 1] += 1
    diff[min(n, i + 1 + present)] -= 1
    diff[i + 1] += diff[i]
    if i + 1 < n:
        a[i + 1] += diff[i + 1]

print(*a)

E問題

餅を小さい組と大きい組で2分する。
このとき、小さい組の小さいほうから順に鏡餅になれるペアを大きい組から探せばいい。
仮に小さい組内で鏡餅になる組み合わせがあったとしても大きい餅が大きい組に対応するようにずらせるので問題ない。

E
from collections import deque

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

first, second = a[:n // 2], a[n // 2:]

q = deque(first)
ans = 0
for a_i in second:
    if q and q[0] * 2 <= a_i:
        ans += 1
        q.popleft()
    else:
        q.append(a_i)

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