結果

問題 No.723 2つの数の和
ユーザー nanaenanae
提出日時 2018-08-03 22:46:19
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,107 bytes
コンパイル時間 1,392 ms
コンパイル使用メモリ 99,900 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2023-09-03 20:50:46
合計ジャッジ時間 2,936 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 23 ms
9,912 KB
testcase_04 AC 28 ms
6,728 KB
testcase_05 AC 27 ms
6,744 KB
testcase_06 AC 27 ms
6,876 KB
testcase_07 AC 13 ms
7,068 KB
testcase_08 AC 15 ms
7,036 KB
testcase_09 AC 28 ms
6,808 KB
testcase_10 AC 13 ms
6,936 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 18 ms
7,304 KB
testcase_13 AC 29 ms
6,816 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 14 ms
7,168 KB
testcase_16 AC 21 ms
7,660 KB
testcase_17 AC 24 ms
6,724 KB
testcase_18 AC 15 ms
4,988 KB
testcase_19 AC 22 ms
5,404 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 34 ms
7,548 KB
testcase_24 AC 10 ms
5,060 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(48): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(60): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(73): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(82): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Edge = Tuple!(int, "u", int, "v");

void main() {
    int n, x;
    scan(n, x);

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

    int[int] asc;
    long ans;

    foreach (i ; 0 .. n) {
        if (a[i] in asc) {
            ans += 2*asc[a[i]];
        }
        if (a[i]*2 == x) {
            ans++;
        }

        if (x - a[i] in asc) {
            asc[x-a[i]]++;
        }
        else {
            asc[x-a[i]] = 1;
        }
    }

    writeln(ans);
}




struct UnionFind {
    private {
        int _size;
        int[] _parent;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
    }
}

































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0