結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー QiToY
提出日時 2026-02-28 13:45:09
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,233 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,442 ms
コンパイル使用メモリ 212,012 KB
実行使用メモリ 10,060 KB
最終ジャッジ日時 2026-02-28 13:45:18
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(unused_imports)]

fn main() {
    input! {
        n: usize, d: i32,
        a: [i32; n],
    }
    let mut l = HashMap::<i32, usize>::new();
    let mut r = HashMap::<i32, usize>::new();
    for &a in &a {
        *r.entry(a).or_default() += 1;
    }
    let mut ans = 0usize;
    for a in a {
        *r.entry(a).or_default() -= 1;
        ans += l.get(&(a-d)).unwrap_or(&0) 
        * r.get(&(a+d)).unwrap_or(&0) ;
        *l.entry(a).or_default() += 1;
    }
    println!("{ans}");
}

use proconio::{input, marker::*};
use itertools::{iproduct, izip, Itertools as _};
use std::{cmp::Reverse, collections::*};

#[macro_export]
macro_rules! chmax {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a < tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
macro_rules! chmin {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a > tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
/// mvec![]
macro_rules! mvec {
    ($val:expr; ()) => {
        $val
    };
    ($val:expr; ($size:expr $(,$rest:expr)*)) => {
        vec![mvec![$val; ($($rest),*)]; $size]
    };
}
0