結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2020-03-22 18:00:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,322 bytes |
コンパイル時間 | 13,632 ms |
コンパイル使用メモリ | 379,640 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-12-25 11:49:07 |
合計ジャッジ時間 | 189,034 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 TLE * 28 |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::collections::VecDeque; #[allow(unused_macros)] macro_rules! read { ([$t:ty] ; $n:expr) => ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>()); ($($t:ty),+ ; $n:expr) => ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>()); ([$t:ty]) => (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>()); ($t:ty) => (rl().parse::<$t>().unwrap()); ($($t:ty),*) => {{ let buf = rl(); let mut w = buf.split_whitespace(); ($(w.next().unwrap().parse::<$t>().unwrap()),*) }}; } #[allow(dead_code)] fn rl() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().to_owned() } trait IteratorExt: Iterator + Sized { fn vec(self) -> Vec<Self::Item> { self.collect() } } impl<T: Iterator> IteratorExt for T {} fn main() { let _ = read!(usize; 1); let v = read!([usize]); // 動的計画法が怪しい println!("{}", max_score(&v)); } fn max_score(s: &[usize]) -> usize { if s.len() == 0 {return 0;} let a = { if s.len() < 2 { s[0] } else { s[0] + max_score(&s[2..]) } }; let b = max_score(&s[1..]); a.max(b) }