結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー |
![]() |
提出日時 | 2020-08-16 17:48:09 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,108 bytes |
コンパイル時間 | 12,577 ms |
コンパイル使用メモリ | 403,780 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 10:35:25 |
合計ジャッジ時間 | 14,461 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 11 |
コンパイルメッセージ
warning: unused import: `std::collections::*` --> src/main.rs:2:5 | 2 | use std::collections::*; | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
ソースコード
use std::cmp::*;use std::collections::*;use std::io::*;use std::str::FromStr;fn read<T: FromStr>() -> T {let stdin = stdin();let stdin = stdin.lock();let token: String = stdin.bytes().map(|c| c.expect("failed to read char") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();token.parse().ok().expect("failed to parse token")}fn main(){let n:usize = read();let a:Vec<i64> = (0..n).map(|_| read()).collect();let mut minf:Vec<i64> = vec![10000000000;n];let mut minb:Vec<i64> = vec![10000000000;n];minf[0] = min(minf[0],a[0]);minb[n - 1] = min(minf[n - 1],a[n - 1]);for i in 1..n{minf[i] = min(minf[i - 1],a[i]);minb[n - 1 - i] = min(minb[n - i], a[n - 1 - i]);}let mut ans:i64 = 1e18 as i64;let mut cnt:i64 = 0;for i in 1..n - 1{if minf[i] < a[i] && minb[i] < a[i]{ans = min(ans,a[i]+minb[i]+minf[i]);cnt += 1;}}if cnt == 0 {ans = -1;}println!("{}",ans);}