結果

問題 No.1285 ゴミ捨て
ユーザー phsplsphspls
提出日時 2022-11-15 11:06:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 12,378 ms
コンパイル使用メモリ 150,460 KB
実行使用メモリ 5,660 KB
最終ジャッジ日時 2023-10-14 16:54:52
合計ジャッジ時間 12,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 29 ms
5,360 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 26 ms
4,832 KB
testcase_11 AC 23 ms
4,792 KB
testcase_12 AC 17 ms
4,372 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 27 ms
5,084 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 6 ms
4,372 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 5 ms
4,372 KB
testcase_21 AC 7 ms
4,372 KB
testcase_22 AC 31 ms
5,612 KB
testcase_23 AC 30 ms
5,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BTreeMap;


fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let a = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: usize = temp.trim().parse().unwrap();
            temp
        })
        .collect::<Vec<_>>();

    let mut mapping = BTreeMap::new();
    for &v in a.iter() { *mapping.entry(v).or_insert(0usize) += 1; }
    let mut prev = 0usize;
    let mut prev_cnt = 0usize;
    let mut result = 0usize;
    for (&val, &cnt) in mapping.iter() {
        if prev + 1 == val {
            result = result.max(prev_cnt + cnt);
        } else {
            result = result.max(cnt);
        }
        prev = val;
        prev_cnt = cnt;
    }
    println!("{}", result);
}
0