結果

問題 No.723 2つの数の和
ユーザー noriocnorioc
提出日時 2018-08-24 00:20:46
言語 D
(dmd 2.107.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 549 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,536 KB
最終ジャッジ日時 2023-09-03 20:53:13
合計ジャッジ時間 579 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.d(1): Error: unable to read module `all`
Main.d(1):        Expected 'std/experimental/all.d' or 'std/experimental/all/package.d' in one of the following import paths:
import path[0] = /opt/d/src/druntime/import/
import path[1] = /opt/d/src/phobos
import path[2] = /dmd2/linux/bin64/../../src/phobos
import path[3] = /dmd2/linux/bin64/../../src/druntime/import

ソースコード

diff #

import std.experimental.all;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

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() {
    auto nx = readints;
    int x = nx[1];
    auto a = readints;
    writeln(calc(x, a));
}
0