結果

問題 No.999 てん vs. ほむ
ユーザー FromBooskaFromBooska
提出日時 2023-02-27 19:47:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,005 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 840,016 KB
最終ジャッジ日時 2023-10-13 04:25:24
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,200 KB
testcase_01 AC 73 ms
71,372 KB
testcase_02 AC 74 ms
71,272 KB
testcase_03 AC 75 ms
71,368 KB
testcase_04 AC 81 ms
75,700 KB
testcase_05 AC 80 ms
75,872 KB
testcase_06 AC 74 ms
70,988 KB
testcase_07 AC 80 ms
76,044 KB
testcase_08 AC 578 ms
392,164 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が何を取るかは自動的に決まる

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

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

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

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

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