結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー elphe
提出日時 2026-02-08 12:20:11
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 4 ms / 5,000 ms
+ 698µs
コード長 931 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 700 ms
コンパイル使用メモリ 180,488 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2026-10-11 11:51:20
合計ジャッジ時間 2,382 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let stdin = std::io::read_to_string(std::io::stdin()).unwrap();
    let mut stdin = stdin.split_ascii_whitespace();

    let n: usize = stdin.next().unwrap().parse().unwrap();
    let x: Vec<u32> = (0..n)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();

    use std::io::Write;
    let mut out = std::io::BufWriter::new(std::io::stdout().lock());
    out.write_all(output(solve(x)).as_bytes()).unwrap();
}

fn solve(x: Vec<u32>) -> u32 {
    let mut count_of = vec![0_u32; 1_000_001];
    x.into_iter().for_each(|x| count_of[x as usize] += 1);
    match count_of
        .into_iter()
        .enumerate()
        .filter(|&(_, c)| c != 0)
        .map(|(i, _)| i as u32)
        .collect::<Vec<_>>()
        .windows(2)
        .map(|x| x[1] - x[0])
        .min()
    {
        Some(ans) => ans,
        None => 0,
    }
}

fn output(ans: u32) -> String {
    ans.to_string() + "\n"
}
0