結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
uw_yu1rabbit
|
| 提出日時 | 2020-08-16 17:50:09 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,126 bytes |
| コンパイル時間 | 13,220 ms |
| コンパイル使用メモリ | 387,304 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-11 10:35:58 |
| 合計ジャッジ時間 | 14,754 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 11 |
ソースコード
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 - 1] < a[i] && minb[i + 1] < a[i]{
ans = min(ans,a[i]+minb[i + 1]+minf[i - 1]);
cnt += 1;
}
}
if cnt == 0 {
ans = -1;
}
println!("{}",ans);
}
uw_yu1rabbit