結果

問題 No.723 2つの数の和
ユーザー taotao54321taotao54321
提出日時 2018-09-27 21:14:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 2,817 ms
コンパイル使用メモリ 151,756 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-02 09:46:31
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 6 ms
4,428 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 6 ms
4,508 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 7 ms
4,448 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 7 ms
4,436 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 7 ms
4,460 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 7 ms
4,440 KB
testcase_24 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };

    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($tokens:expr)  => {};
    ($tokens:expr,) => {};

    // ケツカンマがないパターンも許す
    ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($tokens, $t);
        input_inner! { $tokens $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($tokens:expr, ( $($t:tt),* )) => {
        $(read_value!($tokens, $t)),*
    };

    ($tokens:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($tokens, $t)).collect::<Vec<_>>()
    };

    ($tokens:expr, chars) => {
        read_value!($tokens, String).chars().collect::<Vec<_>>()
    };

    ($tokens:expr, usize1) => {
        read_value!($tokens, usize) - 1
    };

    ($tokens:expr, $t:ty) => {
        $tokens.next().unwrap().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input! {
        N: usize,
        X: i64,
        A: [i64; N],
    }

    let mut cnt = [0; 100001];
    for a in A {
        cnt[a as usize] += 1;
    }

    let mut ans = 0i64;
    for a in 0..100001 {
        let b = X - a;
        if b < 0 || 100000 < b { continue; }
        if a == b {
            let k = cnt[a as usize];
            ans += k*k;
        }
        else {
            ans += cnt[a as usize] * cnt[b as usize];
        }
    }

    println!("{}", ans);
}
0