結果

問題 No.45 回転寿司
ユーザー keibkeib
提出日時 2019-03-05 18:38:35
言語 Swift
(5.10.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 410 bytes
コンパイル時間 3,977 ms
コンパイル使用メモリ 176,308 KB
実行使用メモリ 13,628 KB
最終ジャッジ日時 2023-08-20 12:02:21
合計ジャッジ時間 3,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
13,436 KB
testcase_01 AC 6 ms
13,628 KB
testcase_02 AC 7 ms
13,396 KB
testcase_03 AC 6 ms
13,472 KB
testcase_04 AC 6 ms
13,260 KB
testcase_05 AC 6 ms
13,248 KB
testcase_06 AC 6 ms
13,372 KB
testcase_07 AC 6 ms
13,396 KB
testcase_08 AC 6 ms
13,280 KB
testcase_09 AC 6 ms
13,260 KB
testcase_10 AC 6 ms
13,232 KB
testcase_11 AC 6 ms
13,572 KB
testcase_12 AC 7 ms
13,312 KB
testcase_13 AC 6 ms
13,112 KB
testcase_14 AC 6 ms
13,196 KB
testcase_15 AC 6 ms
13,440 KB
testcase_16 AC 6 ms
13,244 KB
testcase_17 AC 6 ms
13,128 KB
testcase_18 AC 6 ms
13,436 KB
testcase_19 AC 7 ms
13,416 KB
testcase_20 AC 6 ms
13,548 KB
testcase_21 AC 6 ms
13,600 KB
testcase_22 AC 6 ms
13,112 KB
testcase_23 AC 6 ms
13,116 KB
testcase_24 AC 6 ms
13,120 KB
testcase_25 AC 6 ms
13,224 KB
testcase_26 AC 6 ms
13,440 KB
testcase_27 AC 6 ms
13,256 KB
testcase_28 AC 6 ms
13,140 KB
testcase_29 AC 6 ms
13,156 KB
testcase_30 AC 7 ms
13,276 KB
testcase_31 AC 6 ms
13,256 KB
testcase_32 AC 6 ms
13,584 KB
testcase_33 AC 7 ms
13,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation

let n = Int(readLine()!)!
let values = readLine()!.split(separator:" ").map { Int($0)! }
if n == 1 {
    print(values[0])
    exit(0)
}
var dp = Array<Int>(repeating: 0, count: 3)
dp[(n - 1) % 3] = values[n - 1];
dp[(n - 2) % 3] = Swift.max(values[n - 2], values[n - 1])
for i in (0 ..< n-2).reversed() {
    dp[i % 3] = Swift.max(values[i] + dp[(i + 2) % 3], dp[(i + 1) % 3])
}
print(dp[0])
0