結果

問題 No.45 回転寿司
ユーザー keibkeib
提出日時 2019-03-05 18:29:01
言語 Swift
(5.10.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 177,544 KB
実行使用メモリ 13,740 KB
最終ジャッジ日時 2023-08-20 12:01:52
合計ジャッジ時間 4,120 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,484 KB
testcase_01 AC 7 ms
13,352 KB
testcase_02 AC 6 ms
13,516 KB
testcase_03 AC 7 ms
13,520 KB
testcase_04 AC 6 ms
13,740 KB
testcase_05 AC 6 ms
13,144 KB
testcase_06 AC 6 ms
13,272 KB
testcase_07 AC 6 ms
13,392 KB
testcase_08 AC 7 ms
13,364 KB
testcase_09 AC 7 ms
13,192 KB
testcase_10 AC 7 ms
13,160 KB
testcase_11 AC 6 ms
13,148 KB
testcase_12 AC 7 ms
13,268 KB
testcase_13 AC 6 ms
13,144 KB
testcase_14 AC 6 ms
13,548 KB
testcase_15 AC 7 ms
13,240 KB
testcase_16 AC 6 ms
13,144 KB
testcase_17 AC 6 ms
13,324 KB
testcase_18 AC 6 ms
13,504 KB
testcase_19 AC 6 ms
13,308 KB
testcase_20 AC 6 ms
13,220 KB
testcase_21 AC 6 ms
13,308 KB
testcase_22 AC 7 ms
13,656 KB
testcase_23 AC 6 ms
13,504 KB
testcase_24 AC 6 ms
13,420 KB
testcase_25 AC 6 ms
13,536 KB
testcase_26 AC 7 ms
13,412 KB
testcase_27 AC 7 ms
13,728 KB
testcase_28 AC 6 ms
13,540 KB
testcase_29 AC 6 ms
13,540 KB
testcase_30 AC 6 ms
13,428 KB
testcase_31 AC 6 ms
13,652 KB
testcase_32 AC 6 ms
13,224 KB
testcase_33 AC 6 ms
13,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation

let n = Int(readLine()!)!
let values = readLine()!.split(separator:" ").map { Int($0)! }
if n == 1 {
    print(values[0])
    exit(0)
}
if n == 2 {
    print(values.max()!)
    exit(0)
}

var dp = Array<Int>(repeating: -1, count: n)
dp[n - 1] = values[n - 1];
dp[n - 2] = Swift.max(values[n - 2], values[n - 1])
for i in (0 ..< n-2).reversed() {
    dp[i] = Swift.max(values[i] + dp[i + 2], dp[i + 1])
}

print(dp[0])
0