結果

問題 No.723 2つの数の和
コンテスト
ユーザー elphe
提出日時 2026-02-08 19:02:06
言語 Rust
(1.93.0 + proconio + num + itertools)
結果
RE  
実行時間 -
コード長 972 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,699 ms
コンパイル使用メモリ 202,996 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-08 19:02:31
合計ジャッジ時間 4,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 RE * 11
権限があれば一括ダウンロードができます

ソースコード

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: u32 = stdin.next().unwrap().parse().unwrap();
    let a: Vec<u32> = (0..n)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();

    use std::io::Write;
    std::io::stdout()
        .write_all(output(solve(x, a)).as_bytes())
        .unwrap();
}

fn prepare(a: Vec<u32>) -> [u32; 100_001] {
    let mut count_of = [0; 100_001];
    a.into_iter().for_each(|a| count_of[a as usize] += 1);
    count_of
}

fn solve(x: u32, a: Vec<u32>) -> u64 {
    let count_of = prepare(a);
    let mut ans = 0;

    count_of
        .iter()
        .enumerate()
        .take_while(|&(i, _)| i <= x as usize)
        .for_each(|(i, &c)| ans += c as u64 * count_of[x as usize - i] as u64);
    ans
}

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