結果

問題 No.999 てん vs. ほむ
ユーザー FromBooskaFromBooska
提出日時 2023-02-27 21:54:57
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 133,400 KB
最終ジャッジ日時 2023-10-13 06:27:01
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,344 KB
testcase_01 AC 63 ms
71,116 KB
testcase_02 AC 62 ms
71,292 KB
testcase_03 AC 64 ms
71,340 KB
testcase_04 AC 64 ms
71,356 KB
testcase_05 AC 64 ms
71,120 KB
testcase_06 AC 65 ms
71,300 KB
testcase_07 AC 64 ms
71,248 KB
testcase_08 AC 76 ms
76,572 KB
testcase_09 AC 139 ms
126,788 KB
testcase_10 AC 91 ms
88,012 KB
testcase_11 AC 88 ms
83,516 KB
testcase_12 AC 95 ms
93,664 KB
testcase_13 AC 149 ms
133,400 KB
testcase_14 AC 145 ms
133,096 KB
testcase_15 AC 143 ms
133,096 KB
testcase_16 AC 145 ms
133,192 KB
testcase_17 AC 127 ms
109,696 KB
testcase_18 AC 121 ms
108,756 KB
testcase_19 AC 123 ms
109,560 KB
testcase_20 AC 127 ms
109,508 KB
testcase_21 AC 149 ms
133,268 KB
testcase_22 AC 148 ms
132,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 公式解説より
# なんと区間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)
0