結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー tpynerivertpyneriver
提出日時 2020-07-05 14:59:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,033 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 95,856 KB
最終ジャッジ日時 2024-04-22 10:42:01
合計ジャッジ時間 7,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,376 KB
testcase_01 AC 45 ms
53,224 KB
testcase_02 AC 38 ms
53,240 KB
testcase_03 AC 39 ms
53,100 KB
testcase_04 AC 39 ms
53,100 KB
testcase_05 AC 39 ms
52,480 KB
testcase_06 AC 39 ms
53,020 KB
testcase_07 AC 40 ms
52,988 KB
testcase_08 AC 38 ms
52,884 KB
testcase_09 AC 39 ms
53,888 KB
testcase_10 AC 41 ms
57,572 KB
testcase_11 AC 39 ms
52,568 KB
testcase_12 AC 42 ms
57,716 KB
testcase_13 AC 39 ms
52,932 KB
testcase_14 AC 42 ms
58,780 KB
testcase_15 AC 42 ms
59,784 KB
testcase_16 AC 44 ms
57,728 KB
testcase_17 AC 70 ms
76,612 KB
testcase_18 AC 101 ms
81,344 KB
testcase_19 AC 98 ms
80,968 KB
testcase_20 AC 87 ms
80,228 KB
testcase_21 AC 97 ms
80,832 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

INF = 10**15
D = dict()
def rec(i, j, k, l):
    if i+1 == j and k+1 == l:
        return 0
    if (i, j, k, l) in D:
        return D[(i, j, k, l)]
    res = -INF
    if (j-i + l-k) %2 == N%2:
        if i+1 < j:
            res = max(res, C1[i+1]-rec(i+1, j, k, l))
        if k+1 < l:
            res = max(res, C2[k+1]-rec(i, j, k+1, l))
    else:
        if i+1 < j:
            res = max(res, C1[j-1]-rec(i, j-1, k, l))
        if k+1 < l:
            res = max(res, C2[l-1]-rec(i, j, k, l-1))
    
    D[(i, j, k, l)] = res
    return res

N = int(readline())
s, t = map(int, readline().split())
s -= 1
t -= 1

A = list(map(int, readline().split()))
A = A[s:] + A[:s]
t = (t-s)%N

total = sum(A)
X = A[0]
C1 = A[1:t]
C2 = A[N-1:t:-1]
l1 = len(C1)
l2 = len(C2)


if l1 & 1 and l2 & 1:
    X += max(sum(C1[:l1//2])+sum(C2[:1+l2//2]), sum(C1[:1+l1//2])+sum(C2[:l2//2])) 
else:
    X += sum(C1[:(l1+1)//2]) + sum(C2[:(l2+1)//2])
ans = 2*X - total

print(A[0] - A[t] + rec(-1, l1, -1, l2))
0