結果
| 問題 | No.723 2つの数の和 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-08 19:08:35 |
| 言語 | Rust (1.93.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,031 bytes |
| 記録 | |
| コンパイル時間 | 1,304 ms |
| コンパイル使用メモリ | 202,168 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-02-08 19:08:38 |
| 合計ジャッジ時間 | 3,368 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
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; 200_001] {
let mut count_of = [0; 200_001];
a.into_iter().for_each(|a| count_of[a as usize] += 1);
count_of
}
fn solve(x: u32, a: Vec<u32>) -> u64 {
if x > 200_000 {
return 0;
}
let count_of = prepare(a);
let mut ans = 0;
count_of
.iter()
.enumerate()
.take_while(|&(i, _)| i <= x.min(100_000) 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"
}