結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
sino
|
| 提出日時 | 2021-04-08 11:36:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,339 bytes |
| コンパイル時間 | 12,449 ms |
| コンパイル使用メモリ | 400,572 KB |
| 実行使用メモリ | 13,752 KB |
| 最終ジャッジ日時 | 2024-06-23 15:32:27 |
| 合計ジャッジ時間 | 16,724 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 20 |
ソースコード
#[allow(unused_macros)]
macro_rules! read {
([$t:ty] ; $n:expr) =>
((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
($($t:ty),+ ; $n:expr) =>
((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
([$t:ty]) =>
(rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
($t:ty) =>
(rl().parse::<$t>().unwrap());
($($t:ty),*) => {{
let buf = rl();
let mut w = buf.split_whitespace();
($(w.next().unwrap().parse::<$t>().unwrap()),*)
}};
}
#[allow(dead_code)]
fn rl() -> String {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().to_owned()
}
fn main() {
let (_n, x) = read!(usize, usize);
let mut a = read!([usize]);
a.sort();
let mut cnt = 0;
let mut r_max = a.len()-1;
let mut half = 0;
for l in 0..a.len()-1 {
if a[l] + a[l] == x {
half += 1;
}
for r in l+1..=r_max {
match (a[l] + a[r]).cmp(&x) {
std::cmp::Ordering::Equal => {
cnt += 2;
}
std::cmp::Ordering::Greater => {
r_max = r;
break;
}
_ => {}
}
}
}
println!("{}", cnt + half);
}
sino