結果
問題 | No.999 てん vs. ほむ |
ユーザー |
![]() |
提出日時 | 2023-02-27 20:35:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,127 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 82,032 KB |
実行使用メモリ | 126,392 KB |
最終ジャッジ日時 | 2024-09-15 02:36:16 |
合計ジャッジ時間 | 3,314 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 3 |
ソースコード
# 公式解説より # なんと区間dpではない、区間dpで解けるが間に合わない # 全部のゲームを見渡すと、左からkセットでは、先手が左側、後手が右側を取る # 右から(N-k)セットでは、先手が右側、後手が左側を取る # 累積和で高速化して、最大値を探せばいい N = int(input()) A = list(map(int, input().split())) from_left = [] for i in range(N): calc = A[i*2]-A[i*2+1] from_left.append(calc) from_left_cum = [0] temp = 0 for i in range(N): temp += from_left[i] from_left_cum.append(temp) from_right = [] for i in range(N): calc = A[(N-1-i)*2+1]-A[(N-1-i)*2] from_right.append(calc) from_right_cum = [] temp = 0 for i in range(N): temp += from_right[i] from_right_cum.append(temp) from_right = from_right[::-1] from_right_cum = from_right_cum[::-1] from_right_cum.append(0) #print(from_left) #print(from_left_cum) #print(from_right) #print(from_right_cum) ans = -10**20 for i in range(N): #Nより少ないけどまあいいか ans = max(ans, from_left_cum[i]+from_right_cum[i]) print(ans)