結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー elphe
提出日時 2026-02-08 12:20:11
言語 Rust
(1.92.0 + proconio + num + itertools)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 931 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,787 ms
コンパイル使用メモリ 206,004 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-08 12:20:16
合計ジャッジ時間 4,614 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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