結果

問題 No.973 余興
ユーザー mkawa2mkawa2
提出日時 2020-01-18 12:34:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,098 ms / 4,000 ms
コード長 2,274 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 469,640 KB
最終ジャッジ日時 2023-09-09 13:17:18
合計ジャッジ時間 35,907 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,092 ms
469,444 KB
testcase_01 AC 1,070 ms
469,344 KB
testcase_02 AC 1,061 ms
468,956 KB
testcase_03 AC 1,058 ms
468,844 KB
testcase_04 AC 1,070 ms
469,640 KB
testcase_05 AC 1,008 ms
469,192 KB
testcase_06 AC 1,043 ms
468,908 KB
testcase_07 AC 1,023 ms
469,204 KB
testcase_08 AC 1,013 ms
467,880 KB
testcase_09 AC 1,098 ms
469,184 KB
testcase_10 AC 1,039 ms
454,024 KB
testcase_11 AC 348 ms
218,604 KB
testcase_12 AC 346 ms
218,924 KB
testcase_13 AC 343 ms
217,748 KB
testcase_14 AC 348 ms
217,632 KB
testcase_15 AC 136 ms
92,688 KB
testcase_16 AC 140 ms
92,168 KB
testcase_17 AC 121 ms
86,672 KB
testcase_18 AC 130 ms
89,944 KB
testcase_19 AC 132 ms
89,848 KB
testcase_20 AC 119 ms
86,448 KB
testcase_21 AC 139 ms
92,120 KB
testcase_22 AC 140 ms
92,124 KB
testcase_23 AC 129 ms
89,504 KB
testcase_24 AC 127 ms
89,580 KB
testcase_25 AC 112 ms
82,868 KB
testcase_26 AC 121 ms
86,576 KB
testcase_27 AC 148 ms
96,028 KB
testcase_28 AC 133 ms
89,992 KB
testcase_29 AC 128 ms
89,436 KB
testcase_30 AC 685 ms
469,376 KB
testcase_31 AC 679 ms
469,364 KB
testcase_32 AC 677 ms
469,104 KB
testcase_33 AC 684 ms
468,664 KB
testcase_34 AC 732 ms
467,208 KB
testcase_35 AC 755 ms
469,484 KB
testcase_36 AC 708 ms
458,712 KB
testcase_37 AC 708 ms
458,684 KB
testcase_38 AC 721 ms
468,036 KB
testcase_39 AC 716 ms
468,280 KB
testcase_40 AC 72 ms
71,248 KB
testcase_41 AC 71 ms
71,380 KB
testcase_42 AC 71 ms
71,156 KB
testcase_43 AC 71 ms
70,920 KB
testcase_44 AC 71 ms
71,200 KB
testcase_45 AC 87 ms
75,560 KB
testcase_46 AC 822 ms
469,292 KB
testcase_47 AC 775 ms
468,992 KB
testcase_48 AC 826 ms
469,460 KB
testcase_49 AC 755 ms
438,892 KB
testcase_50 AC 813 ms
466,112 KB
testcase_51 AC 820 ms
469,456 KB
testcase_52 AC 1,091 ms
469,332 KB
testcase_53 AC 905 ms
462,984 KB
testcase_54 AC 1,074 ms
469,628 KB
testcase_55 AC 953 ms
469,604 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(残り1つの状態)に遷移できれば勝ちで確定
    # 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
            # (和<遷移先のマスの数)ならば、どこかのマスは0なので勝ち
            # lを動かすとき
            nl = lto[l]  # 最遠の遷移先
            if nl >= r or dpl[l + 1][r] - dpl[min(nl + 1, n - 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