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?

ABC475のPython解答(A~D)

0
Posted at

AtCoder Beginner Contest 475の解答等の速報的まとめ

A問題

oを各文字の後につける。
最後に余計な文字がつくので消す。

A
s = input()

ans = list()
for s_i in s:
    ans.append(s_i)
    ans.append("o")

print("".join(ans[:-1]))

B問題

でかい数字から引いた下3桁がおつりと一致する

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

ans = [0, 0, 0]
for a_i in a:
    b_i = 10 ** 5 - a_i
    for i in range(3):
        ans[i] += b_i % 10
        b_i //= 10

print(*ans)

C問題

両端を固定して$S$から端の近いほうまで+端から端までの距離を見ていく

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

dist = [0]
for a_i in a:
    dist.append(dist[-1] + a_i)

s -= 1
ans = 0
for left in range(s + 1):
    for right in range(s, n):
        if min(dist[s] - dist[left], dist[right] - dist[s]) + dist[right] - dist[left] <= l:
            ans = max(ans, right - left + 1)

print(ans)

D問題

文字に対する数字の対応と数字に対する文字の対応を両方確認する

D
def get_prime(limit):
    primes = [False] + [True] * limit
    primes[1] = False
    i = 2
    while i * i <= limit:
        if primes[i]:
            for j in range(i * i, limit + 1, i):
                primes[j] = False

        i += 1

    return [i for i in range(limit + 1) if primes[i]]


s = input()
n = len(s)

mini, maxi = 10 ** (n - 1), 10 ** n

prime_list = get_prime(10 ** 7)
for p in prime_list:
    if p <= mini:
        continue
    if maxi <= p:
        break
    str_p = str(p)
    d_s = dict()
    d_p = dict()
    flg = True
    for p_i, s_i in zip(str_p, s):
        if s_i in d_s or p_i in d_p:
            if s_i not in d_s or p_i not in d_p or d_s[s_i] != p_i or d_p[p_i] != s_i:
                flg = False
                break
        else:
            d_s[s_i] = p_i
            d_p[p_i] = s_i
    if flg:
        print(p)
        exit()

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