結果

問題 No.45 回転寿司
ユーザー pluto77pluto77
提出日時 2016-02-27 17:01:11
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 407 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 6,740 KB
実行使用メモリ 6,232 KB
最終ジャッジ日時 2023-08-27 14:36:57
合計ジャッジ時間 1,811 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,956 KB
testcase_01 AC 11 ms
6,024 KB
testcase_02 AC 11 ms
6,104 KB
testcase_03 AC 12 ms
5,980 KB
testcase_04 AC 12 ms
6,016 KB
testcase_05 AC 10 ms
5,860 KB
testcase_06 AC 11 ms
6,176 KB
testcase_07 AC 11 ms
6,176 KB
testcase_08 AC 10 ms
5,932 KB
testcase_09 AC 11 ms
5,964 KB
testcase_10 AC 11 ms
5,912 KB
testcase_11 AC 10 ms
6,060 KB
testcase_12 AC 11 ms
6,232 KB
testcase_13 AC 11 ms
5,880 KB
testcase_14 AC 11 ms
5,992 KB
testcase_15 AC 12 ms
5,976 KB
testcase_16 AC 11 ms
5,872 KB
testcase_17 AC 11 ms
6,172 KB
testcase_18 AC 11 ms
6,068 KB
testcase_19 AC 12 ms
6,192 KB
testcase_20 AC 10 ms
5,940 KB
testcase_21 AC 10 ms
5,884 KB
testcase_22 AC 10 ms
5,860 KB
testcase_23 AC 10 ms
5,856 KB
testcase_24 AC 10 ms
5,856 KB
testcase_25 AC 11 ms
6,104 KB
testcase_26 AC 11 ms
6,112 KB
testcase_27 AC 12 ms
6,028 KB
testcase_28 AC 11 ms
5,908 KB
testcase_29 AC 11 ms
5,960 KB
testcase_30 AC 12 ms
5,940 KB
testcase_31 AC 11 ms
5,856 KB
testcase_32 AC 10 ms
5,940 KB
testcase_33 AC 13 ms
5,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
##yuki_45
import sys

n=int(raw_input())
v=map(int,raw_input().split())

if n==1:
 print v[0]
 sys.exit()
elif n==2:
 print max(v[0],v[1])
 sys.exit()

dp=[[-1 for i in xrange(2)] for j in xrange(n)]

dp[0][1]=v[0]
dp[1][0]=v[0]
dp[1][1]=v[1]

for i in xrange(2,n):
 dp[i][0]=max(dp[i-1][1],dp[i-2][1])
 dp[i][1]=max(dp[i-1][0]+v[i],dp[i-2][1]+v[i])

res=max(dp[n-1][0],dp[n-1][1])
print res
0