1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

エイシングプログラミングコンテスト2021(AtCoder Beginner Contest 202) 参戦記

Last updated at Posted at 2021-05-22

エイシングプログラミングコンテスト2021(AtCoder Beginner Contest 202) 参戦記

ABC202A - Three Dice

1分で突破. 書くだけ.

a, b, c = map(int, input().split())

print(21 - (a + b + c))

ABC202B - 180°

3分で突破. 書くだけ.

S = input()

d = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'}
print(''.join(d[c] for c in reversed(S)))

ABC202C - Made Up

11分半で突破、TLE1. Aに含まれる値 a に対して、同じ値である B のインデックスの値を求め、そのインデックスの値と同じ値が C にいくつ含まれているかを求めれば良い.

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

x = Counter(A)
y = Counter(B[c - 1] for c in C)

result = 0
for a in x:
    if a not in y:
        continue
    result += x[a] * y[a]
print(result)

ABC202D - aab aba baa

作れる文字列の総数は重複組合せで求められる. 次の文字を 'a' としたときの組み合わせの数を求めてそれを K と比較すれば一文字づつ確定していくことができる.

A, B, K = map(int, input().split())


def comb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    a = 1
    b = 1
    for i in range(k):
        a *= n - i
        b *= k - i
    return a // b


def h(n, k):
    return comb(n + k - 1, k)


n = 0
result = ''
a, b = A, B
while a != 0 and b != 0:
    t = h(b + 1, a - 1)
    if n + t >= K:
        result += 'a'
        a -= 1
    else:
        result += 'b'
        b -= 1
        n += t
result += 'a' * a + 'b' * b
print(result)
1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?