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?

トヨタ自動車プログラミングコンテスト2024#12(AtCoder Beginner Contest 384)の解答等の速報的まとめ

A問題

c1と一致しなかったやつをc2に置き換える

A
n, c1, c2 = input().split()
s = input()

ans = []
for s_i in s:
    ans.append(c1 if c1 == s_i else c2)

print(*ans, sep="")

B問題

問題文の通り

B
n, r = map(int, input().split())

for _ in range(n):
    d, a = map(int, input().split())
    if d == 1 and 1600 <= r <= 2799:
        r += a
    elif d == 2 and 1200 <= r <= 2399:
        r += a

print(r)

C問題

全参加者のスコアを計算してソートする

C
p = list(map(int, input().split()))

data = []
for bit in range(1, 1 << 5):
    name = ""
    score = 0
    for i in range(5):
        if bit >> i & 1:
            name += chr(ord("A") + i)
            score += p[i]
    data.append((-score, name))

data.sort()
for _, name in data:
    print(name)

D問題

根本は尺取り法
複数回Aを跨ぐと尺取りはうまくいかないので、事前に合計でmodを取って端の部分だけ尺取りを行えばいいようにSを小さくする

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

if s >= sum(a):
    s = s % sum(a)

a += a

left = 0
sum_a = 0
for right in range(n * 2):
    while left < right and sum_a > s:
        sum_a -= a[left]
        left += 1
    if sum_a == s:
        exit(print("Yes"))

    sum_a += a[right]

print("No")

E問題

自身に隣接するスライムをheapqで管理して、小さいほうから吸収できるか確かめていく

E
from heapq import heappop, heappush

h, w, x = map(int, input().split())
p, q = map(lambda x:int(x) - 1, input().split())

field = [list(map(int, input().split())) for _ in range(h)]

check = [[False] * w for _ in range(h)]
check[p][q] = True
power = field[p][q]
heap = []
for i, j in [(p, q + 1), (p, q - 1), (p + 1, q), (p - 1, q)]:
    if 0 <= i < h and 0 <= j < w:
        heappush(heap, (field[i][j], i, j))
        check[i][j] = True

while heap and heap[0][0] * x < power:
    p_i, x_i, y_i = heappop(heap)
    power += p_i
    for i, j in [(x_i, y_i + 1), (x_i, y_i - 1), (x_i + 1, y_i), (x_i - 1, y_i)]:
        if 0 <= i < h and 0 <= j < w and not check[i][j]:
            heappush(heap, (field[i][j], i, j))
            check[i][j] = True

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