3
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?

ABC414をPythonで(A~D)

Posted at

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

A問題

問題文通りにシミュレーション

A
n, l, r = map(int, input().split())
ans = 0

for _ in range(n):
    x, y = map(int, input().split())
    if x <= l and r <= y:
        ans += 1

print(ans)

B問題

そのままやる
ただ、$l$が100を超えていたら文字列を生成せずにToo Longを返さないとエラーになる

B
ans = ""
for _ in range(int(input())):
    c, l = input().split()
    l = int(l)
    if l + len(ans) > 100:
        exit(print("Too Long"))

    ans += c * l

print(ans)

C問題

10進数で回文の数字を生成して、A進数でも回文になるか確かめる

C
from collections import deque

def make_number(lst):
    return int("".join(lst))


def check_num(m):
    lst = list()
    while m:
        lst.append(m % a)
        m //= a

    return lst == lst[::-1]

a = int(input())
n = int(input())

ans = 0

q = deque()
q.append(list())
while q:
    lst = q.popleft()
    for i in range(0, 10):
        if lst == list() and i == 0:
            continue
        num_1 = make_number(lst + [str(i)] + lst[::-1])
        num_2 = make_number(lst + [str(i), str(i)] + lst[::-1])
        if num_1 <= n:
            if check_num(num_1):
                ans += num_1
        if num_2 <= n:
            if check_num(num_2):
                ans += num_2
            if make_number(lst + [str(i), "0", str(i)] + lst[::-1]) <= n:
                q.append(lst + [str(i)])

print(ans)

D問題

家を$M$個のグループにして、各グループの中心に基地局を置く
グループは距離が近いほうからまとめていく

D
n, m = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(set(x))

diff = list()
for x_i, x_j in zip(x, x[1:]):
    diff.append(x_j - x_i)

diff.sort(reverse=True)
ans = 0
while len(diff) >= m:
    d_i = diff.pop()
    ans += d_i

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