結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
13,508 KB
testcase_01 AC 7 ms
13,848 KB
testcase_02 AC 7 ms
13,708 KB
testcase_03 AC 6 ms
13,548 KB
testcase_04 AC 7 ms
13,292 KB
testcase_05 AC 6 ms
13,420 KB
testcase_06 AC 7 ms
13,464 KB
testcase_07 AC 6 ms
13,288 KB
testcase_08 AC 6 ms
13,252 KB
testcase_09 AC 7 ms
13,516 KB
testcase_10 AC 6 ms
13,164 KB
testcase_11 AC 6 ms
13,148 KB
testcase_12 AC 7 ms
13,520 KB
testcase_13 AC 6 ms
13,268 KB
testcase_14 AC 6 ms
13,264 KB
testcase_15 AC 7 ms
13,360 KB
testcase_16 AC 6 ms
13,232 KB
testcase_17 AC 6 ms
13,244 KB
testcase_18 AC 6 ms
13,732 KB
testcase_19 AC 7 ms
13,316 KB
testcase_20 AC 5 ms
13,328 KB
testcase_21 AC 6 ms
13,240 KB
testcase_22 AC 6 ms
13,512 KB
testcase_23 AC 6 ms
13,236 KB
testcase_24 AC 6 ms
13,224 KB
testcase_25 AC 6 ms
13,388 KB
testcase_26 AC 7 ms
13,284 KB
testcase_27 AC 7 ms
13,392 KB
testcase_28 AC 6 ms
13,436 KB
testcase_29 AC 7 ms
13,272 KB
testcase_30 AC 6 ms
13,744 KB
testcase_31 AC 6 ms
13,392 KB
testcase_32 AC 6 ms
13,420 KB
testcase_33 AC 7 ms
13,300 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[2] = values[n - 1];
dp[1] = Swift.max(values[n - 2], values[n - 1])
for i in (0 ..< n-2).reversed() {
    let j = (i + 1002 - n) % 3
    dp[j] = Swift.max(values[i] + dp[(j + 2) % 3], dp[(j + 1) % 3])
}
print(dp[(1002 - n) % 3])
0