結果

問題 No.2260 Adic Sum
ユーザー DaylightDaylight
提出日時 2023-05-09 12:02:53
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 3,332 bytes
コンパイル時間 4,219 ms
コンパイル使用メモリ 230,232 KB
実行使用メモリ 25,404 KB
最終ジャッジ日時 2023-09-04 20:20:13
合計ジャッジ時間 7,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 23 ms
11,228 KB
testcase_15 AC 30 ms
13,532 KB
testcase_16 AC 20 ms
9,068 KB
testcase_17 AC 32 ms
13,552 KB
testcase_18 AC 215 ms
24,840 KB
testcase_19 AC 238 ms
25,384 KB
testcase_20 AC 162 ms
24,828 KB
testcase_21 AC 169 ms
25,404 KB
testcase_22 AC 141 ms
24,884 KB
testcase_23 AC 106 ms
23,896 KB
testcase_24 AC 229 ms
24,960 KB
testcase_25 AC 45 ms
14,588 KB
testcase_26 AC 44 ms
14,492 KB
testcase_27 AC 46 ms
14,536 KB
testcase_28 AC 44 ms
14,552 KB
testcase_29 AC 47 ms
15,300 KB
testcase_30 AC 52 ms
15,952 KB
testcase_31 AC 211 ms
19,728 KB
testcase_32 AC 212 ms
19,896 KB
testcase_33 AC 56 ms
15,568 KB
testcase_34 AC 92 ms
21,444 KB
testcase_35 AC 368 ms
25,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public import std;

DList!string scan_buffer;
DList!char char_buffer;
static this() {
    scan_buffer = DList!(string)();
    char_buffer = DList!(char)();
}

void cin()() {

}

void cin(T, A...)(ref T a, ref A tail) {
    import std.traits : isArray;

    static if (typeof(a).stringof == "string") {
        if (!char_buffer.empty) {
            a = char_buffer.array.map!(x => x.to!string).join();
            char_buffer.clear();
        } else {
            while (scan_buffer.empty) {
                foreach (t; readln.split) {
                    if (t.length == 0) {
                        continue;
                    }
                    scan_buffer.insert(t);
                }
            }
            auto token = scan_buffer.front;
            scan_buffer.removeFront();
            a = token;
        }
    } else static if (typeof(a).stringof == "char") {
        if (!char_buffer.empty) {
            a = char_buffer.front();
            char_buffer.removeFront();
        } else {
            while (scan_buffer.empty) {
                foreach (t; readln.split) {
                    if (t.length == 0) {
                        continue;
                    }
                    scan_buffer.insert(t);
                }
            }
            auto token = scan_buffer.front;
            scan_buffer.removeFront();
            a = token[0];
            if (token.length > 1) {
                foreach (c; token[1 .. $]) {
                    char_buffer.insertBack(c);
                }
            }
        }
    } else static if (typeof(a).stringof == "char[]") {
        if (a.length == 0) {
            string token;
            cin(token);
            foreach (c; token) {
                a ~= c;
            }
        } else {
            foreach (ref v; a) {
                cin(v);
            }
        }
    } else static if (isArray!(typeof(a))) {
        foreach (ref v; a) {
            cin(v);
        }
    } else static if (isTuple!(typeof(a))) {
        foreach (i, _; a) {
            cin(a[i]);
        }
    } else {
        if (!char_buffer.empty) {
            writeln(char_buffer.array.map!(x => x.to!string));
            a = char_buffer.array.map!(x => x.to!string).join().to!T;
            char_buffer.clear();
        } else {
            while (scan_buffer.empty) {
                foreach (t; readln.split) {
                    if (t.length == 0) {
                        continue;
                    }
                    scan_buffer.insert(t);
                }
            }
            auto token = scan_buffer.front;
            scan_buffer.removeFront();
            a = token.to!T;
        }
    }
    cin(tail);
}

bool chmin(T)(ref T a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

bool chmax(T)(ref T a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

alias PQueue(T = long, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main() {
    long N, P;
    cin(N, P);
    auto A = new int[](N);
    cin(A);
    int M = A.maxElement;
    long nP = P;
    long ans = 0;
    while (nP <= M) {
        int[int] map;
        foreach (a; A) {
            ans += map.get(a % nP, 0);
            map[a % nP] = map.get(a % nP, 0) + 1;
        }
        nP *= P;
    }
    ans.writeln;
}
0