結果

問題 No.973 余興
ユーザー mkawa2mkawa2
提出日時 2020-01-18 12:38:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,200 ms / 4,000 ms
コード長 2,270 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 469,768 KB
最終ジャッジ日時 2023-09-09 13:27:03
合計ジャッジ時間 34,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,200 ms
469,556 KB
testcase_01 AC 1,026 ms
469,320 KB
testcase_02 AC 1,011 ms
469,160 KB
testcase_03 AC 1,004 ms
468,932 KB
testcase_04 AC 1,015 ms
469,336 KB
testcase_05 AC 970 ms
469,036 KB
testcase_06 AC 997 ms
468,816 KB
testcase_07 AC 980 ms
469,248 KB
testcase_08 AC 962 ms
467,820 KB
testcase_09 AC 1,049 ms
469,768 KB
testcase_10 AC 975 ms
453,812 KB
testcase_11 AC 338 ms
218,612 KB
testcase_12 AC 338 ms
218,924 KB
testcase_13 AC 335 ms
217,492 KB
testcase_14 AC 334 ms
217,532 KB
testcase_15 AC 127 ms
92,316 KB
testcase_16 AC 131 ms
92,068 KB
testcase_17 AC 115 ms
86,664 KB
testcase_18 AC 123 ms
89,896 KB
testcase_19 AC 125 ms
89,704 KB
testcase_20 AC 114 ms
86,648 KB
testcase_21 AC 132 ms
92,200 KB
testcase_22 AC 132 ms
92,092 KB
testcase_23 AC 120 ms
89,604 KB
testcase_24 AC 120 ms
89,672 KB
testcase_25 AC 109 ms
82,460 KB
testcase_26 AC 116 ms
86,604 KB
testcase_27 AC 143 ms
96,380 KB
testcase_28 AC 124 ms
89,692 KB
testcase_29 AC 124 ms
89,736 KB
testcase_30 AC 644 ms
469,408 KB
testcase_31 AC 641 ms
469,164 KB
testcase_32 AC 648 ms
468,964 KB
testcase_33 AC 651 ms
469,276 KB
testcase_34 AC 692 ms
467,488 KB
testcase_35 AC 696 ms
469,144 KB
testcase_36 AC 684 ms
458,672 KB
testcase_37 AC 679 ms
458,668 KB
testcase_38 AC 688 ms
468,348 KB
testcase_39 AC 695 ms
468,284 KB
testcase_40 AC 70 ms
71,336 KB
testcase_41 AC 70 ms
71,080 KB
testcase_42 AC 69 ms
71,272 KB
testcase_43 AC 68 ms
71,076 KB
testcase_44 AC 69 ms
71,112 KB
testcase_45 AC 84 ms
75,392 KB
testcase_46 AC 780 ms
469,184 KB
testcase_47 AC 703 ms
468,908 KB
testcase_48 AC 780 ms
469,324 KB
testcase_49 AC 725 ms
438,560 KB
testcase_50 AC 779 ms
466,184 KB
testcase_51 AC 788 ms
469,344 KB
testcase_52 AC 1,026 ms
469,616 KB
testcase_53 AC 824 ms
462,892 KB
testcase_54 AC 1,019 ms
469,488 KB
testcase_55 AC 896 ms
469,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n, x = MI()
    aa = LI()
    # 閉区間[l,r]が残っている状態で手順が来たとき、勝てるかどうかをDPする
    # lが現在の位置からどこまで移動できるかを事前計算する
    lto = [0] * n
    to = -1
    s = 0
    for l in range(n):
        while to < n - 1 and s <= x:
            to += 1
            s += aa[to]
        lto[l] = to
        s -= aa[l]
    # print(lto)
    # rが現在の位置からどこまで移動できるかを事前計算する
    rto = [0] * n
    to = n
    s = 0
    for r in range(n - 1, -1, -1):
        while to > 0 and s <= x:
            to -= 1
            s += aa[to]
        rto[r] = to
        s -= aa[r]
    # print(rto)
    # l<rを守ったうえで、lは大きい方から、rは小さい方からDP[l][r]を更新
    # 遷移先に1つでも負け(0)があれば勝ち(1)、そうでなければ(すべて1なら)負け(0)
    # ただし、遷移先が複数あり、愚直にやるとTLEするので
    # lとr別々に累積和の表を持って、0の遷移先があるか判断する
    dpl = [[0] * n for _ in range(n)]
    dpr = [[0] * n for _ in range(n)]
    win = 0
    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            win = 0
            # l=r(残り1つの状態)に遷移できれば勝ちで確定
            # (和<遷移先のマスの数)ならば、どこかのマスは0なので勝ち
            # lを動かすとき
            nl = lto[l]  # 最遠の遷移先
            if nl >= r or dpl[l + 1][r] - dpl[nl + 1][r] < nl - l: win = 1
            # rを動かすとき
            nr = rto[r]  # 最遠の遷移先
            if nr <= l or dpr[l][r - 1] - dpr[l][nr - 1] < r - nr: win = 1
            # 表を更新
            dpl[l][r] = dpl[l + 1][r] + win
            dpr[l][r] = dpr[l][r - 1] + win
    if win:
        print("A")
    else:
        print("B")

main()
0