ABC401振り返り



前回の振り返り

https://qiita.com/comet725/items/56cc52727b9f01ef6be2

今日はABC401開催日だったので参加結果を振り返る


https://atcoder.jp/contests/abc401

今週はA,B,Cの完(0ペナ)


# A

if文一発で終わるけど
`Yes`,`No`形式じゃないのが少し厄介

## ソースコード

```python:main.py
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 = rI()
    ans = 200 <= S <= 299
    print('Success' if ans else 'Failure')
    
if __name__ == '__main__':
    main()

```

# B

login状態を変数で持ってfor文を回す
ログアウトした状態でprivateを見た回数をカウント

## ソースコード

```python:main.py
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 = rI()
    login = False
    cnt = 0
    for i in range(N):
        S = rS()
        if S == "login":
            login = True
        if S == "logout":
            login = False
        if S == "private" and not login:
            cnt += 1
    
    print(cnt)
    
if __name__ == '__main__':
    main()

```

# C

累積和と思ったら微妙に違った
K個総和用の変数作って
次の値きめたらその値を足して
K個から溢れた一番うしろの値を引く

## ソースコード

```python:main.py
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)

class ModInt:
    def __init__(self, x, mod = 10**9):
        self.mod = mod
        self.x = x.x if isinstance(x, ModInt) else x % self.mod
    __str__ = lambda self:str(self.x)
    __repr__ = __str__
    __int__ = lambda self: self.x
    __index__ = __int__
    __add__ = lambda self, other: ModInt(self.x + ModInt(other).x)
    __sub__ = lambda self, other: ModInt(self.x - ModInt(other).x)
    __mul__ = lambda self, other: ModInt(self.x * ModInt(other).x)
    __pow__ = lambda self, other: ModInt(pow(self.x, ModInt(other).x, self.mod))
    __truediv__ = lambda self, other: ModInt(self.x * pow(ModInt(other).x, self.mod - 2, self.mod))
    __floordiv__ = lambda self, other: ModInt(self.x // ModInt(other).x)
    __lt__ = lambda self, other: self.x < ModInt(other).x
    __gt__ = lambda self, other: self.x > ModInt(other).x
    __le__ = lambda self, other: self.x <= ModInt(other).x
    __ge__ = lambda self, other: self.x >= ModInt(other).x
    __eq__ = lambda self, other: self.x == ModInt(other).x
    __ne__ = lambda self, other: self.x!= ModInt(other).x

class mint(ModInt):
    pass

def main():
    N, K = rLI()
    M = N+K+1
    A = [mint(1)] * (M)
    S = [mint(i) for i in range(M)]
    
    a = mint(K)
    for i in range(K,M):
        A[i] = a
        a += a
        a -= A[i-K]
    err(A[K-1:min(len(A),K+10)])
    err(S[K-1:min(len(S),K+10)])
    print(A[N])
    
if __name__ == '__main__':
    main()

```

# D
適当にやってみたけどWA

解説みたら丁寧な場合分けが必要だったようだ

# E

unionfind使って数えそうって思ったのはニアピンだったようだ

# F

問題文見てそっ閉じした

# G

Nが小さくて全探索しそうっておもったけど
二部グラフの最大マッチングとか考えないといけないのね…

# 感想
今回のようなD問題が安定して解ければ緑維持できるんだろうね。