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?

ABC462のPython解答(A~E)

0
Posted at

CodeQUEEN 2026 予選 (AtCoder Beginner Contest 462)の解答等の速報的まとめ

A問題

数字かどうか判定して結合

A
s = input()

ans = list()
for s_i in s:
    if s_i.isnumeric():
        ans.append(s_i)

print(*ans, sep="")

B問題

シミュレーション

B
n = int(input())
ans = [list() for _ in range(n)]

for i in range(1, n + 1):
    k, *arg = map(lambda x:int(x) - 1, input().split())
    for a_i in arg:
        ans[a_i].append(i)

for ans_i in ans:
    print(len(ans_i), end=" ")
    print(*ans_i)

C問題

$x$が小さいほうから確認
それまでに出た$y$未満の$y$ならカウント

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

p.sort()
min_y = 10 ** 6
ans = 0
for x_i, y_i in p:
    if y_i <= min_y:
        ans += 1
        min_y = y_i

print(ans)

D問題

時刻ごとにSortedListへ退出時間を入れてD立ったときにいる人の人数から答えを計算する

D
from sortedcontainers import SortedList

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

s = SortedList([])
ind = 0
ans = 0
for time in range(10 ** 6 + 10):
    while ind < n and data[ind][0] <= time:
        s.add(data[ind][1])
        ind += 1

    target = len(s) - s.bisect_left(time + d)

    if target >= 2:
        ans += target * (target - 1) // 2

    while s and s[0] <= time:
        s.pop(0)

print(ans)

E問題

$x,y$は絶対値をとっても結果は同じ
内包する正方形の頂点までコストの小さいほうで移動する
残りの直線は、高いほうのコストが低いほうの3倍以上ある場合は3手使ってU字で進んだほうが良いのを踏まえて計算する

E
for _ in range(int(input())):
    a, b, x, y = map(int, input().split())

    x, y = abs(x), abs(y)

    if a * 3 < b:
        b = a * 3
    if b * 3 < a:
        a = b * 3

    even, odd = 0, 0
    diff = abs(x - y)
    if x > y:
        even = (diff + 1) // 2 * a
        odd = diff // 2 * b
    elif x < y:
        even = (diff + 1) // 2 * b
        odd = diff // 2 * a

    print(min(x, y) * 2 * min(a, b) + even + odd)
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?