結果
問題 | No.999 てん vs. ほむ |
ユーザー |
![]() |
提出日時 | 2023-02-27 21:54:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 1,244 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 132,288 KB |
最終ジャッジ日時 | 2024-09-15 03:42:12 |
合計ジャッジ時間 | 3,647 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
# 公式解説より # なんと区間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) integrated = [] for i in range(N+1): integrated.append(from_left_cum[i]+from_right_cum[i]) #print(from_left) #print(from_left_cum) #print(from_right) #print(from_right_cum) #print(integrated) ans = -10**20 for i in range(N+1): #Nより少ないけどまあいいか ans = max(ans, from_left_cum[i]+from_right_cum[i]) print(ans)