結果

問題 No.1110 好きな歌
ユーザー fukafukatanifukafukatani
提出日時 2020-10-10 10:17:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 321 ms / 5,000 ms
コード長 1,236 bytes
コンパイル時間 2,677 ms
コンパイル使用メモリ 146,888 KB
実行使用メモリ 5,644 KB
最終ジャッジ日時 2023-09-27 21:09:50
合計ジャッジ時間 11,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 177 ms
4,376 KB
testcase_25 AC 217 ms
4,576 KB
testcase_26 AC 115 ms
4,380 KB
testcase_27 AC 216 ms
4,580 KB
testcase_28 AC 123 ms
4,376 KB
testcase_29 AC 264 ms
5,096 KB
testcase_30 AC 118 ms
4,376 KB
testcase_31 AC 74 ms
4,380 KB
testcase_32 AC 286 ms
5,308 KB
testcase_33 AC 136 ms
4,380 KB
testcase_34 AC 189 ms
4,376 KB
testcase_35 AC 286 ms
5,540 KB
testcase_36 AC 31 ms
4,376 KB
testcase_37 AC 84 ms
4,380 KB
testcase_38 AC 259 ms
5,088 KB
testcase_39 AC 189 ms
4,376 KB
testcase_40 AC 223 ms
4,840 KB
testcase_41 AC 18 ms
4,376 KB
testcase_42 AC 260 ms
5,384 KB
testcase_43 AC 262 ms
5,104 KB
testcase_44 AC 291 ms
5,624 KB
testcase_45 AC 306 ms
5,624 KB
testcase_46 AC 300 ms
5,632 KB
testcase_47 AC 318 ms
5,628 KB
testcase_48 AC 304 ms
5,544 KB
testcase_49 AC 291 ms
5,628 KB
testcase_50 AC 306 ms
5,644 KB
testcase_51 AC 293 ms
5,616 KB
testcase_52 AC 306 ms
5,644 KB
testcase_53 AC 321 ms
5,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    }
}
0