結果
問題 | No.2260 Adic Sum |
ユーザー |
|
提出日時 | 2023-05-09 12:02:53 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 310 ms / 2,000 ms |
コード長 | 3,332 bytes |
コンパイル時間 | 2,770 ms |
コンパイル使用メモリ | 233,980 KB |
実行使用メモリ | 24,780 KB |
最終ジャッジ日時 | 2024-06-22 17:54:34 |
合計ジャッジ時間 | 6,421 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
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;}