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?

今回はPythonでABC414をABCを解くことができたので、ABC415直前ですが振り返ろうと思います。
(今週はあまりにも忙しすぎて、備忘録が遅くなってしまいました)

コンテスト概要

ミラティブ プログラミングコンテスト2025(AtCoder Beginner Contest 414)

開催日:2025年7月12日 21:00-22:40


A - Streamer Takahashi

方針

入力値XYについて、
XL以下かつYR以上となっていらばカウントするというもの。

N, L, R = map(int, input().split())
count = 0

for _ in range(N):
    X, Y = map(int, input().split())
    if X <= L and Y >= R:
        count += 1

print(count)

B - String Too Long

方針

連長圧縮(ランレングス圧縮)を復元する問題に対して、効率よく処理する問題。

N = int(input())
total_length = 0
result = []

for _ in range(N):
    c, l = input().split()
    l = int(l)
    total_length += l
    if total_length > 100:
        print("Too Long")
        exit()
    result.append(c * l)

print("".join(result))

C - Palindromic in Both Bases

方針

xxxx

A = int(input())
N = int(input())

total = 0
used = set()

# 1桁の回文(1~9)
for i in range(1, 10):
    if i <= N:
        s = str(i)
        # A進数変換
        x = i
        digits = []
        while x > 0:
            digits.append(str(x % A))
            x //= A
        if digits == digits[::-1]:
            total += i
            used.add(i)

# 2桁以上の回文(偶数・奇数桁)
for half in range(1, 10**6):  # 6桁以上は N=10^12 でも安全
    s = str(half)

    # 偶数桁: 123 + 321 → 123321
    even_pal = int(s + s[::-1])
    if even_pal <= N and even_pal not in used:
        x = even_pal
        digits = []
        while x > 0:
            digits.append(str(x % A))
            x //= A
        if digits == digits[::-1]:
            total += even_pal
            used.add(even_pal)

    # 奇数桁: 123 + 21 → 12321
    odd_pal = int(s + s[:-1][::-1])
    if odd_pal <= N and odd_pal not in used:
        x = odd_pal
        digits = []
        while x > 0:
            digits.append(str(x % A))
            x //= A
        if digits == digits[::-1]:
            total += odd_pal
            used.add(odd_pal)

print(total)

結果

ABC 3完
順位 4017th / 12324
パフォーマンス 836
レーティング 535 → 586 (+51)

感想

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?