結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-08-16 17:48:09
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 168,756 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 18:25:37
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 0 ms
6,816 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 0 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 0 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 0 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 1 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 21 ms
6,940 KB
testcase_24 AC 20 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 19 ms
6,940 KB
testcase_29 AC 19 ms
6,940 KB
testcase_30 AC 19 ms
6,940 KB
testcase_31 AC 19 ms
6,940 KB
testcase_32 AC 19 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::*`
 --> main.rs:2:5
  |
2 | use std::collections::*;
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

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);
}
0