結果

問題 No.1110 好きな歌
ユーザー akakimidoriakakimidori
提出日時 2020-07-10 21:37:25
言語 Rust
(1.77.0)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 2,045 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 165,468 KB
実行使用メモリ 9,364 KB
最終ジャッジ日時 2024-04-19 16:13:36
合計ジャッジ時間 6,013 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 53 ms
6,336 KB
testcase_25 AC 71 ms
7,208 KB
testcase_26 AC 33 ms
5,376 KB
testcase_27 AC 70 ms
7,148 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 79 ms
8,064 KB
testcase_30 AC 35 ms
5,376 KB
testcase_31 AC 21 ms
5,376 KB
testcase_32 AC 94 ms
8,748 KB
testcase_33 AC 38 ms
5,416 KB
testcase_34 AC 57 ms
6,540 KB
testcase_35 AC 89 ms
9,348 KB
testcase_36 AC 8 ms
5,376 KB
testcase_37 AC 22 ms
5,376 KB
testcase_38 AC 76 ms
7,936 KB
testcase_39 AC 54 ms
6,428 KB
testcase_40 AC 68 ms
7,760 KB
testcase_41 AC 4 ms
5,376 KB
testcase_42 AC 86 ms
8,384 KB
testcase_43 AC 79 ms
7,936 KB
testcase_44 AC 93 ms
9,360 KB
testcase_45 AC 97 ms
9,240 KB
testcase_46 AC 97 ms
9,360 KB
testcase_47 AC 107 ms
9,240 KB
testcase_48 AC 97 ms
9,232 KB
testcase_49 AC 87 ms
9,356 KB
testcase_50 AC 99 ms
9,232 KB
testcase_51 AC 96 ms
9,232 KB
testcase_52 AC 99 ms
9,364 KB
testcase_53 AC 102 ms
9,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        d: i32,
        a: [i32; n],
    }
    let mut b = vec![];
    for a in a.iter() {
        b.push((*a, 1));
        b.push((*a - d, 0));
    }
    b.push((std::i32::MIN, 0));
    b.sort();
    b.dedup_by(|a, b| {
        b.0 == a.0 && {
            b.1 += a.1;
            true
        }
    });
    let mut s = vec![0; b.len()];
    for i in 1..b.len() {
        s[i] = s[i - 1] + b[i].1;
    }
    for a in a {
        let k = b.binary_search_by(|p| p.0.cmp(&(a - d))).unwrap();
        writeln!(out, "{}", s[k]).ok();
    }
}

fn main() {
    run();
}
0