Atcoder ABC257 振り返り
A - A to Z String 2【AC】
文字と数字を変換するにはordとchrを使います.Aはunicodeで65なのでそれに1ずつ+していくとBCD...と文字と用意できます.
N, X = map(int, input().split()) ans = "" for i in range(26): ans += chr(65+i)*N print(ans[X-1])
B - 1D Pawn【AC】
Q回全てシミュレーションします.一番右にいたり隣にコマが存在したらcontinueします.
N, K , Q = map(int, input().split()) A = [int(i) for i in input().split()] L = [int(i) for i in input().split()] for i in range(Q): ind = L[i] - 1 if A[ind] == N: continue if ind < K-1 and A[ind] + 1 == A[ind+1]: continue A[ind] += 1 print(*A)
C - Robot Takahashi【AC】
Wはソートしても問題無いことを利用します.ソートするときSの大人か子供かの情報も必要なので辞書を用意し大人と子供の人数を数えます.辞書にしているのは同じ体重が複数人いたときにそれぞれ人数を加算できるようにするためです.
W=sorted(W)として,f(X)のXをX
N = int(input()) S = list(map(int, list(input()))) adult = S.count(1) child = S.count(0) W = [int(i) for i in input().split()] dic = {} for i, w in enumerate(W): dic.setdefault(w, {0:0, 1:0}) dic[w][S[i]] += 1 W = sorted(set(W)) ans = adult a = 0 c = 0 for w in W: c += dic[w][0] a += dic[w][1] ans = max(ans, adult - a + c) print(ans)