結果

問題 No.1110 好きな歌
ユーザー akakimidoriakakimidori
提出日時 2020-07-10 21:37:25
言語 Rust
(1.77.0)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 2,045 bytes
コンパイル時間 3,794 ms
コンパイル使用メモリ 155,184 KB
実行使用メモリ 9,396 KB
最終ジャッジ日時 2023-08-01 16:57:47
合計ジャッジ時間 7,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 64 ms
7,244 KB
testcase_25 AC 77 ms
7,928 KB
testcase_26 AC 38 ms
4,952 KB
testcase_27 AC 77 ms
7,748 KB
testcase_28 AC 42 ms
5,184 KB
testcase_29 AC 92 ms
8,380 KB
testcase_30 AC 41 ms
5,184 KB
testcase_31 AC 25 ms
4,380 KB
testcase_32 AC 103 ms
9,036 KB
testcase_33 AC 46 ms
5,564 KB
testcase_34 AC 66 ms
7,412 KB
testcase_35 AC 104 ms
9,304 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 28 ms
4,468 KB
testcase_38 AC 89 ms
8,416 KB
testcase_39 AC 66 ms
7,312 KB
testcase_40 AC 80 ms
8,352 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 96 ms
8,920 KB
testcase_43 AC 90 ms
8,332 KB
testcase_44 AC 107 ms
9,364 KB
testcase_45 AC 116 ms
9,296 KB
testcase_46 AC 112 ms
9,376 KB
testcase_47 AC 115 ms
9,396 KB
testcase_48 AC 111 ms
9,384 KB
testcase_49 AC 103 ms
9,292 KB
testcase_50 AC 113 ms
9,384 KB
testcase_51 AC 109 ms
9,320 KB
testcase_52 AC 112 ms
9,324 KB
testcase_53 AC 114 ms
9,332 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