結果

問題 No.723 2つの数の和
ユーザー kokatsukokatsu
提出日時 2021-10-11 00:18:41
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 3,453 ms
コンパイル使用メモリ 208,740 KB
実行使用メモリ 8,212 KB
最終ジャッジ日時 2023-09-04 14:26:53
合計ジャッジ時間 4,770 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 29 ms
5,836 KB
testcase_04 AC 38 ms
7,536 KB
testcase_05 AC 33 ms
6,708 KB
testcase_06 AC 37 ms
7,736 KB
testcase_07 AC 16 ms
4,576 KB
testcase_08 AC 19 ms
4,604 KB
testcase_09 AC 38 ms
7,308 KB
testcase_10 AC 16 ms
4,504 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 22 ms
5,472 KB
testcase_13 AC 37 ms
7,320 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 16 ms
4,824 KB
testcase_16 AC 24 ms
7,080 KB
testcase_17 AC 32 ms
7,944 KB
testcase_18 AC 25 ms
8,212 KB
testcase_19 AC 31 ms
6,900 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 26 ms
8,172 KB
testcase_24 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N, X;
    readf("%d %d\n", N, X);

    auto a = readln.chomp.split.to!(int[]);

    a.sort;
    auto b = a.assumeSorted;

    long res;
    while (!b.empty) {
        int f = b.front;
        if (b.contains(X-f)) {
            auto l = b.equalRange(X-f).length;
            if (X == 2 * f) {
                res += 2 * l - 1;
            }
            else {
                res += 2 * l;
            }
        }
        b.popFront;
    }

    res.writeln;
}
0