結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2022-06-09 10:21:40 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 788 bytes |
| コンパイル時間 | 12,776 ms |
| コンパイル使用メモリ | 402,996 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-21 05:28:45 |
| 合計ジャッジ時間 | 14,059 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 RE * 1 |
| other | AC * 30 |
ソースコード
use std::io::Read;
const INF:usize=usize::MAX>>2;
fn main(){
let mut input = "".to_owned();
std::io::stdin().read_to_string(&mut input).unwrap();
let mut input = input.split_ascii_whitespace();
macro_rules! read(($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap()));
let n=read!(usize);
let mut v=vec![!0;n];
for i in 0..n{
v[i]=read!(usize);
}
if n==1{
println!("{}",v[0]);
}
if n==2{
println!("{}",v[0].max(v[1]));
}
else{
let mut dp=vec![INF;n];
dp[0]=v[0];
dp[1]=v[1];
for i in 2..n{
dp[i]=dp[i-1];
for j in 0..i-1{
dp[i]=dp[i].max(dp[j]+v[i]);
}
}
println!("{}",dp[n-1]);
}
}