結果

問題 No.973 余興
ユーザー neterukun
提出日時 2020-01-19 16:16:09
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 825 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 277,692 KB
最終ジャッジ日時 2024-07-02 21:51:47
合計ジャッジ時間 46,774 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 RE * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

n, x = map(int, input().split())
a = list(map(int, input().split()))

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + a[i]
    

def solve(l, r):
    # [l, r)のシュークリームが残っているときの先手の勝ち負け
    if r - l == 0:
        dp[l][r] = True
        return True
    if r - l == 1:
        dp[l][r] = False
        return False
    if dp[l][r] is not None:
        return dp[l][r]

    tmp = False
    for newl in range(l + 1, r + 1):
        if ruiseki[newl] - ruiseki[l] <= x:
            tmp |= not solve(newl, r)
    for newr in range(l, r):
        if ruiseki[r] - ruiseki[newr] <= x:
            tmp |= not solve(l, newr)
    dp[l][r] = tmp
    
    return tmp

dp = [[None] * (n + 1) for i in range(n + 1)]
if solve(0, n):
    print("A")
else:
    print("B")
0