結果

問題 No.999 てん vs. ほむ
ユーザー FromBooskaFromBooska
提出日時 2023-02-27 20:19:12
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,073 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 846,376 KB
最終ジャッジ日時 2023-10-13 04:54:08
合計ジャッジ時間 4,417 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,104 KB
testcase_01 AC 72 ms
71,236 KB
testcase_02 AC 73 ms
71,152 KB
testcase_03 AC 74 ms
71,184 KB
testcase_04 AC 78 ms
76,016 KB
testcase_05 AC 81 ms
75,948 KB
testcase_06 AC 75 ms
71,304 KB
testcase_07 AC 81 ms
75,948 KB
testcase_08 AC 272 ms
156,604 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 区間dpの変形版
# secondの番はない、secondが何を取るかは自動的に決まる
# MLE出たのでdp表の0の分を無くして小さくした

# 区間dpは混乱する、dp[l][r]だが実装はwidth, l

N = int(input())
A = [0]+[0]+list(map(int, input().split()))

# dp[l][r] 区間[l, r]での最高得点
dp = [[0]*(N+1) for i in range(N+1)]

for width in range(0, N):
    # width 0から更新、確定
    # 区間が広がっていく方向に更新
    # つまり1区間狭い区間のmaxから今の区間の値が決まる
    # 最大widthはN-1でよい、なぜなら両側inclusiveだから、答えもそう参照する
    for l in range(1, N-width+1):
        r = l + width
        #print('width', width, 'l', l, 'r', r)
        # r=l+1 はwidth 0
            
        if width > 0:
            dp[l][r] = max(A[l*2]-A[l*2+1]+ dp[l+1][r], dp[l][r-1]-A[r*2]+A[r*2+1])
        else:
            dp[l][r] = max(A[l*2], A[l*2+1]) - min(A[l*2+1], A[l*2])
            # 最後の1つからポイントは取れない

ans = dp[1][N]
print(ans)
0