結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-09-25 21:33:00 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,593 bytes |
コンパイル時間 | 898 ms |
コンパイル使用メモリ | 108,788 KB |
実行使用メモリ | 20,412 KB |
最終ジャッジ日時 | 2023-09-04 10:07:05 |
合計ジャッジ時間 | 6,324 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
11,028 KB |
testcase_01 | AC | 47 ms
13,124 KB |
testcase_02 | AC | 46 ms
12,348 KB |
testcase_03 | AC | 47 ms
11,076 KB |
testcase_04 | AC | 46 ms
11,012 KB |
testcase_05 | AC | 48 ms
13,112 KB |
testcase_06 | AC | 47 ms
11,580 KB |
testcase_07 | AC | 47 ms
11,016 KB |
testcase_08 | AC | 47 ms
11,836 KB |
testcase_09 | AC | 48 ms
11,780 KB |
testcase_10 | AC | 50 ms
12,692 KB |
testcase_11 | AC | 51 ms
13,552 KB |
testcase_12 | AC | 53 ms
12,168 KB |
testcase_13 | AC | 52 ms
12,264 KB |
testcase_14 | AC | 54 ms
12,012 KB |
testcase_15 | AC | 82 ms
20,108 KB |
testcase_16 | AC | 83 ms
20,412 KB |
testcase_17 | AC | 83 ms
19,972 KB |
testcase_18 | AC | 83 ms
20,268 KB |
testcase_19 | AC | 82 ms
20,000 KB |
testcase_20 | AC | 82 ms
20,312 KB |
testcase_21 | AC | 81 ms
19,892 KB |
testcase_22 | AC | 82 ms
20,208 KB |
testcase_23 | AC | 81 ms
19,936 KB |
testcase_24 | AC | 83 ms
20,260 KB |
testcase_25 | AC | 82 ms
19,992 KB |
testcase_26 | AC | 81 ms
20,240 KB |
testcase_27 | AC | 46 ms
11,084 KB |
testcase_28 | AC | 46 ms
11,080 KB |
testcase_29 | WA | - |
testcase_30 | AC | 62 ms
15,304 KB |
testcase_31 | AC | 63 ms
14,780 KB |
testcase_32 | AC | 76 ms
18,272 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum E = 18; void hadamard(long[] fs) { foreach (e; 0 .. E) { foreach (p; 0 .. 1 << E) { if (!(p & 1 << e)) { const tmp = fs[p] - fs[p | 1 << e]; fs[p] += fs[p | 1 << e]; fs[p | 1 << e] = tmp; } } } } void main() { try { for (; ; ) { const N = readInt(); const X = readInt(); auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt(); } auto fs0 = new long[1 << E]; auto fs1 = new long[1 << E]; foreach (i; 0 .. N) { fs0[A[i]] += 1; fs1[A[i]] += A[i]; } fs0.hadamard; fs1.hadamard; auto gs0 = new long[1 << E]; auto gs1 = new long[1 << E]; foreach (h; 0 .. 1 << E) { gs0[h] = fs0[h]^^2; gs1[h] = fs0[h] * fs1[h]; } gs0.hadamard; gs1.hadamard; gs0[] /= 1 << E; gs1[] /= 1 << E; debug { writeln("gs0 = ", gs0[0 .. 1 << 4]); writeln("gs1 = ", gs1[0 .. 1 << 4]); } long ans; // or = (xor + sum) / 2 foreach (h; 0 .. 1 << E) { if (h < X) { ans += gs0[h] * h; ans += gs1[h]; ans += gs1[h]; } } ans /= 2; foreach (i; 0 .. N) { if ((A[i] ^ A[i]) < X) { ans -= A[i] | A[i]; } } ans /= 2; writeln(ans); } } catch (EOFException e) { } }