AtCoder「エクサウィザーズ 2019」をPythonで解く
AtCoder「エクサウィザーズ 2019」に出て、2完でした。
ABCのA, B問題を全て埋めていた甲斐があり、3分で2完できました。C問題はTLEが取れませんでした。
昼休みに2問解いて、ABCのA, B埋め完了〜🎉C, Dも仕上げていくぞ💪 pic.twitter.com/KNsTUJsJ7a
— u++ (@upura0) March 22, 2019
A - Regular Triangle(100点)
- AとBとCが全部一致しているか否か
A, B, C = list(map(int, input().split())) if ((A == B) and (B == C)): print("Yes") else: print("No")
B - Red or Blue(200点)
- S内のR, Bの数をそれぞれ数えて比較
N = int(input()) S = input() R = S.count('R') B = S.count('B') if (R > B): print("Yes") else: print("No")
C - Snuke the Wizard(500点)
- 愚直に解いたらTLE
N, Q = list(map(int, input().split())) S = input() spell = [list(input().split()) for i in range(Q)] D = {} for i, s in enumerate(S): if s in D: D[s].append(i) else: D[s] = [i] G = [1 for _ in range(N)] loss = 0 for sp in spell: if sp[0] in D: for d in D[sp[0]]: if sp[1] == 'L': if d != 0: G[d-1] += G[d] else: loss += G[d] G[d] = 0 elif sp[1] == 'R': if d != (N-1): G[d+1] += G[d] else: loss += G[d] G[d] = 0 print(N - loss)