結果
問題 | No.484 収穫 |
ユーザー | mio_h |
提出日時 | 2017-02-12 23:45:52 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 104 ms / 3,000 ms |
コード長 | 2,843 bytes |
コンパイル時間 | 12,497 ms |
コンパイル使用メモリ | 377,936 KB |
実行使用メモリ | 64,768 KB |
最終ジャッジ日時 | 2024-10-13 13:14:04 |
合計ジャッジ時間 | 14,736 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 102 ms
64,640 KB |
testcase_13 | AC | 100 ms
64,640 KB |
testcase_14 | AC | 101 ms
64,768 KB |
testcase_15 | AC | 101 ms
64,768 KB |
testcase_16 | AC | 102 ms
64,768 KB |
testcase_17 | AC | 101 ms
64,768 KB |
testcase_18 | AC | 104 ms
64,512 KB |
testcase_19 | AC | 102 ms
64,640 KB |
testcase_20 | AC | 102 ms
64,768 KB |
testcase_21 | AC | 104 ms
64,640 KB |
testcase_22 | AC | 102 ms
64,640 KB |
testcase_23 | AC | 104 ms
64,768 KB |
コンパイルメッセージ
warning: use of deprecated method `std::error::Error::description`: use the Display impl or to_string() --> src/main.rs:65:62 | 65 | Err(why) => panic!("error in read_line: {}", why.description()), | ^^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
ソースコード
use std::io::{self, Stdin}; use std::str::{self, FromStr}; use std::error::Error; use std::thread; use std::cmp::*; const INF: i64 = 1e16 as i64; fn exec() { let mut sc = Scanner::new(); let n: usize = sc.ne(); let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect(); let mut dp_l = vec![vec![INF; n]; n]; let mut dp_r = dp_l.clone(); dp_l[0][n - 1] = a[0]; dp_r[0][n - 1] = a[n - 1]; for len in (1..n).rev() { for i in 0..n - len + 1 { let j = i + len - 1; let mut res_l = INF; let mut res_r = INF; if i > 0 { res_l = min(res_l, dp_l[i - 1][j] + 1); res_r = min(res_r, dp_l[i - 1][j] + len as i64); } if j < n - 1 { res_l = min(res_l, dp_r[i][j + 1] + len as i64); res_r = min(res_r, dp_r[i][j + 1] + 1); } dp_l[i][j] = max(a[i], res_l); dp_r[i][j] = max(a[j], res_r); } } let ans = (0..n).fold(INF, |mi, i| min(mi, dp_l[i][i])); println!("{}", ans); } fn main() { const DEFAULT_STACK: usize = 16 * 1024 * 1024; let builder = thread::Builder::new(); let th = builder.stack_size(DEFAULT_STACK); let handle = th.spawn(|| { exec(); }).unwrap(); let _ = handle.join(); } #[allow(dead_code)] struct Scanner { stdin: Stdin, id: usize, buf: Vec<u8>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), id: 0, buf: Vec::new(), } } fn next_line(&mut self) -> Option<String> { let mut res = String::new(); match self.stdin.read_line(&mut res) { Ok(0) => return None, Ok(_) => Some(res), Err(why) => panic!("error in read_line: {}", why.description()), } } fn next<T: FromStr>(&mut self) -> Option<T> { while self.buf.len() == 0 { self.buf = match self.next_line() { Some(r) => { self.id = 0; r.trim().as_bytes().to_owned() } None => return None, }; } let l = self.id; assert!(self.buf[l] != b' '); let n = self.buf.len(); let mut r = l; while r < n && self.buf[r] != b' ' { r += 1; } let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() { Ok(s) => Some(s), Err(_) => panic!("parse error"), }; while r < n && self.buf[r] == b' ' { r += 1; } if r == n { self.buf.clear(); } else { self.id = r; } res } fn ne<T: FromStr>(&mut self) -> T { self.next::<T>().unwrap() } }