筆者はレート800前後の茶~緑コーダ
ABC428のA,B,C問題を解いていく
A
divmodの使い方むずい
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
import os
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
IS_LOCAL = int(os.getenv("ATCODER", "0"))==0
err = (lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)) if IS_LOCAL else (lambda *args, **kwargs: None)
def main():
S, A, B, X = rLI()
q, r = divmod(X, A+B)
ans = S * (A*q + min(r, A))
print(ans)
if __name__ == '__main__':
main()
B
内包表記とCouterの組み合わせ技
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
import os
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
IS_LOCAL = int(os.getenv("ATCODER", "0"))==0
err = (lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)) if IS_LOCAL else (lambda *args, **kwargs: None)
def main():
N, K = rLI()
S = rS()
T = [S[i:i+K] for i in range(N-K+1)]
c = Counter(T)
m = max(c.values())
print(m)
U = sorted([k for k, v in c.items() if v == m])
print(*U)
if __name__ == '__main__':
main()
C
スタックの組み合わせ技だけど
異常に沼った
最小値を保存してでマイナスだったらNGという部分の理解がコアっぽい
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
import os
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
IS_LOCAL = int(os.getenv("ATCODER", "0"))==0
err = (lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)) if IS_LOCAL else (lambda *args, **kwargs: None)
def main():
Q = rI()
T = [0]
c = [0]
b = 0
d = {"(": 1, ")": -1}
for _ in range(Q):
q = rLS()
if q[0] == "1":
t = q[1]
b += d[t]
T.append(b)
c.append(min(c[-1],b))
elif q[0] == "2":
T.pop()
c.pop()
b = T[-1]
if c[-1] < 0:
print("No")
else:
print("Yes" if T[-1] == 0 else "No")
if __name__ == '__main__':
main()
感想
たまにはD,E以外の問題を解くのも刺激になるね。