結果
問題 | No.999 てん vs. ほむ |
ユーザー | FromBooska |
提出日時 | 2023-02-27 20:20:47 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,073 bytes |
コンパイル時間 | 631 ms |
コンパイル使用メモリ | 10,760 KB |
実行使用メモリ | 176,228 KB |
最終ジャッジ日時 | 2023-10-13 04:55:29 |
合計ジャッジ時間 | 4,983 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
12,156 KB |
testcase_01 | AC | 16 ms
7,940 KB |
testcase_02 | AC | 16 ms
7,800 KB |
testcase_03 | AC | 16 ms
7,812 KB |
testcase_04 | AC | 18 ms
7,904 KB |
testcase_05 | AC | 21 ms
8,176 KB |
testcase_06 | AC | 17 ms
7,876 KB |
testcase_07 | AC | 19 ms
8,300 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
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 | -- | - |
ソースコード
# 区間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)