結果

問題 No.1438 Broken Drawers
ユーザー fukafukatani
提出日時 2021-04-03 10:35:42
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 14,931 ms
コンパイル使用メモリ 387,212 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2024-12-24 13:37:06
合計ジャッジ時間 17,410 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut a = a
        .iter()
        .enumerate()
        .map(|(i, &x)| (x, i))
        .collect::<Vec<_>>();
    a.sort();
    let mut used = vec![false; n];
    let mut ans = 0;
    for (_, i) in a {
        if i < n - 1 && used[i + 1] {
            continue;
        }
        used[i] = true;
        ans += 1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0