結果

問題 No.723 2つの数の和
ユーザー noriocnorioc
提出日時 2020-03-15 23:45:06
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 3,668 ms
コンパイル使用メモリ 161,976 KB
実行使用メモリ 6,720 KB
最終ジャッジ日時 2023-09-04 06:19:49
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 12 ms
6,436 KB
testcase_04 AC 15 ms
6,472 KB
testcase_05 AC 14 ms
6,652 KB
testcase_06 AC 14 ms
6,420 KB
testcase_07 AC 8 ms
4,804 KB
testcase_08 AC 9 ms
4,904 KB
testcase_09 AC 15 ms
6,372 KB
testcase_10 AC 7 ms
6,636 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 9 ms
6,204 KB
testcase_13 AC 15 ms
6,400 KB
testcase_14 AC 5 ms
4,560 KB
testcase_15 AC 8 ms
5,048 KB
testcase_16 AC 10 ms
6,240 KB
testcase_17 AC 13 ms
6,368 KB
testcase_18 AC 10 ms
6,116 KB
testcase_19 AC 17 ms
6,676 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 15 ms
6,720 KB
testcase_24 AC 6 ms
4,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

long calc(int x, int[] a) {
    auto freq = new int[](a.maxElement + 1);
    foreach (e; a)
        freq[e]++;

    long ans = 0;
    foreach (e; a) {
        int y = x - e;
        if (0 <= y && y < freq.length)
            ans += freq[y];
    }
    return ans;
}

void main() {
    int n, x; scan(n, x);
    auto a = readints;
    writeln(calc(x, a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
0