結果

問題 No.2854 -1 Subsequence
ユーザー ryuuichiryuuichi
提出日時 2024-08-25 15:46:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 878 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 58,436 KB
最終ジャッジ日時 2024-08-25 15:47:12
合計ジャッジ時間 19,871 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 676 ms
46,892 KB
testcase_01 AC 650 ms
44,968 KB
testcase_02 AC 679 ms
46,484 KB
testcase_03 AC 410 ms
29,968 KB
testcase_04 AC 767 ms
50,924 KB
testcase_05 AC 513 ms
35,952 KB
testcase_06 AC 285 ms
24,880 KB
testcase_07 AC 717 ms
49,500 KB
testcase_08 AC 129 ms
16,048 KB
testcase_09 AC 525 ms
38,656 KB
testcase_10 AC 878 ms
55,304 KB
testcase_11 AC 842 ms
55,432 KB
testcase_12 AC 846 ms
55,428 KB
testcase_13 AC 864 ms
55,304 KB
testcase_14 AC 831 ms
55,432 KB
testcase_15 AC 846 ms
55,912 KB
testcase_16 AC 871 ms
55,556 KB
testcase_17 AC 845 ms
55,904 KB
testcase_18 AC 848 ms
55,968 KB
testcase_19 AC 843 ms
55,432 KB
testcase_20 AC 872 ms
53,592 KB
testcase_21 AC 844 ms
52,948 KB
testcase_22 AC 833 ms
58,436 KB
testcase_23 AC 27 ms
10,752 KB
testcase_24 AC 26 ms
10,752 KB
testcase_25 AC 27 ms
10,752 KB
testcase_26 AC 27 ms
10,752 KB
testcase_27 AC 27 ms
10,752 KB
testcase_28 AC 26 ms
10,752 KB
testcase_29 AC 30 ms
10,624 KB
testcase_30 AC 27 ms
10,624 KB
testcase_31 AC 28 ms
10,624 KB
testcase_32 AC 26 ms
10,752 KB
testcase_33 AC 26 ms
10,752 KB
testcase_34 AC 27 ms
10,752 KB
testcase_35 AC 27 ms
10,752 KB
testcase_36 AC 28 ms
10,624 KB
testcase_37 AC 28 ms
10,752 KB
testcase_38 AC 27 ms
10,624 KB
testcase_39 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(-A[0])
    quit()
dp=[[-float("inf"),-float("inf")]for _ in range(N)]
#dp[i][偶数 偶数]=i個まで選択した時の最大(偶奇毎)
dp[0][1]=-A[0]
dp[1][1]=-(min(A[0],A[1]))
dp[1][0]=-A[0]+A[1]
""" for i in range(2,N):
    for j in range(2):
        dp[i][j]=max(dp[i-1][j],dp[i-1][j^1]+A[i]*(-1)**j) """


for i in range(N-1):
    for j in range(2):
        dp[i+1][j^1]=max(dp[i][j]+A[i+1]*(-1)**(j+1),dp[i][j^1],dp[i+1][j^1],(-A[i+1] if j==0 else -float("inf")))

print(max(dp[-1]))
0