結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
mottodora
|
| 提出日時 | 2016-10-23 12:54:46 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 878 bytes |
| コンパイル時間 | 12,788 ms |
| コンパイル使用メモリ | 403,252 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-24 17:42:10 |
| 合計ジャッジ時間 | 14,288 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 WA * 1 |
ソースコード
use std::cmp;
fn getline() -> String{
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok();
return ret;
}
fn getvec(string: String) -> Vec<i32> {
string.trim().split_whitespace()
.map(|s| s.parse().unwrap())
.collect()
}
fn solve(t: i32) -> i32 {
let v = getvec(getline());
let mut table = [0; 1000];
table[0] = v[0];
table[1] = if t == 1 { 0 } else {v[1]};
table[2] = if t < 3 { 0 }
else if table[0]+v[2]>v[1] {table[0]+v[2]}
else {v[1]};
for i in 3..t {
let a = table[(i-1) as usize];
let b = table[(i-2) as usize]+v[i as usize];
let c = table[(i-3) as usize]+v[i as usize];
table[i as usize] = cmp::max(cmp::max(a, b), c);
}
return table[(t-1) as usize]
}
fn main() {
let t:i32 = getline().trim().parse().unwrap();
println!("{}", solve(t));
}
mottodora