結果

問題 No.258 回転寿司(2)
ユーザー ayaoniayaoni
提出日時 2020-12-28 10:26:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 55,240 KB
最終ジャッジ日時 2024-04-10 08:51:29
合計ジャッジ時間 6,432 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,356 KB
testcase_01 AC 40 ms
54,844 KB
testcase_02 AC 41 ms
53,232 KB
testcase_03 AC 36 ms
52,256 KB
testcase_04 AC 37 ms
52,948 KB
testcase_05 AC 38 ms
54,552 KB
testcase_06 AC 38 ms
53,776 KB
testcase_07 AC 37 ms
52,964 KB
testcase_08 AC 37 ms
52,688 KB
testcase_09 AC 38 ms
52,816 KB
testcase_10 AC 36 ms
53,084 KB
testcase_11 AC 37 ms
54,116 KB
testcase_12 AC 38 ms
54,372 KB
testcase_13 AC 39 ms
53,748 KB
testcase_14 AC 38 ms
53,456 KB
testcase_15 AC 37 ms
54,004 KB
testcase_16 AC 37 ms
53,724 KB
testcase_17 AC 35 ms
53,076 KB
testcase_18 AC 38 ms
54,900 KB
testcase_19 AC 36 ms
53,428 KB
testcase_20 AC 38 ms
54,404 KB
testcase_21 AC 39 ms
53,992 KB
testcase_22 AC 36 ms
53,012 KB
testcase_23 AC 36 ms
53,288 KB
testcase_24 AC 35 ms
52,980 KB
testcase_25 AC 36 ms
52,652 KB
testcase_26 AC 38 ms
55,040 KB
testcase_27 AC 37 ms
52,900 KB
testcase_28 AC 38 ms
55,240 KB
testcase_29 AC 37 ms
53,600 KB
testcase_30 AC 36 ms
52,964 KB
testcase_31 AC 36 ms
53,712 KB
testcase_32 AC 36 ms
53,428 KB
testcase_33 AC 38 ms
53,816 KB
testcase_34 AC 38 ms
54,044 KB
testcase_35 AC 37 ms
52,684 KB
testcase_36 AC 36 ms
52,620 KB
testcase_37 AC 37 ms
53,136 KB
testcase_38 AC 38 ms
53,020 KB
testcase_39 AC 37 ms
53,872 KB
testcase_40 AC 40 ms
54,432 KB
testcase_41 AC 41 ms
53,356 KB
testcase_42 AC 39 ms
52,920 KB
testcase_43 AC 39 ms
53,420 KB
testcase_44 AC 38 ms
53,320 KB
testcase_45 AC 38 ms
53,420 KB
testcase_46 AC 37 ms
52,860 KB
testcase_47 AC 38 ms
54,368 KB
testcase_48 AC 37 ms
52,696 KB
testcase_49 AC 35 ms
52,688 KB
testcase_50 AC 36 ms
53,504 KB
testcase_51 AC 37 ms
53,012 KB
testcase_52 AC 38 ms
54,572 KB
testcase_53 AC 36 ms
53,444 KB
testcase_54 AC 41 ms
52,948 KB
testcase_55 AC 39 ms
54,444 KB
testcase_56 AC 38 ms
54,648 KB
testcase_57 AC 37 ms
52,580 KB
testcase_58 AC 38 ms
53,696 KB
testcase_59 AC 39 ms
54,328 KB
testcase_60 AC 39 ms
52,660 KB
testcase_61 AC 39 ms
53,428 KB
testcase_62 AC 37 ms
53,136 KB
testcase_63 AC 39 ms
54,056 KB
testcase_64 AC 38 ms
53,816 KB
testcase_65 AC 40 ms
53,376 KB
testcase_66 AC 36 ms
53,132 KB
testcase_67 AC 38 ms
53,700 KB
testcase_68 AC 39 ms
53,824 KB
testcase_69 AC 38 ms
52,944 KB
testcase_70 AC 37 ms
52,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
V = [0]+LI()

if N == 1:
    print(V[1])
    print(1)
    exit()

dp = [0]*(N+1)
prev = [0]*(N+1)
dp[1] = V[1]
dp[2] = V[2]
for i in range(3,N+1):
    if dp[i-2] >= dp[i-3]:
        prev[i] = i-2
        dp[i] = dp[i-2]+V[i]
    else:
        prev[i] = i-3
        dp[i] = dp[i-3]+V[i]

if dp[-1] >= dp[-2]:
    ANS = [N]
    X = N
    while prev[X] != 0:
        ANS.append(prev[X])
        X = prev[X]
    ANS.reverse()
    print(dp[-1])
    print(*ANS)
else:
    ANS = [N-1]
    X = N-1
    while prev[X] != 0:
        ANS.append(prev[X])
        X = prev[X]
    ANS.reverse()
    print(dp[-2])
    print(*ANS)
0