結果
問題 |
No.1110 好きな歌
|
ユーザー |
![]() |
提出日時 | 2020-10-10 10:17:55 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 292 ms / 5,000 ms |
コード長 | 1,236 bytes |
コンパイル時間 | 14,084 ms |
コンパイル使用メモリ | 377,212 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-07-20 15:42:11 |
合計ジャッジ時間 | 22,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
fn main() { let v = read_vec::<i64>(); let (n, d) = (v[0] as usize, v[1]); let mut a = vec![0; n]; for i in 0..n { a[i] = read::<i64>(); } let mut a_sorted = a.clone(); a_sorted.sort(); for anum in a { let ans = a_sorted.upper_bound(&(anum - d)); println!("{}", ans); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } use std::cmp::Ordering; pub trait BinarySearch<T> { fn upper_bound(&self, x: &T) -> usize; } impl<T: Ord> BinarySearch<T> for [T] { fn upper_bound(&self, x: &T) -> usize { let mut low = 0; let mut high = self.len(); while low != high { let mid = (low + high) / 2; match self[mid].cmp(x) { Ordering::Less | Ordering::Equal => { low = mid + 1; } Ordering::Greater => { high = mid; } } } low } }