結果
問題 | No.1209 XOR Into You |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-08-30 14:04:51 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 2,846 bytes |
コンパイル時間 | 988 ms |
コンパイル使用メモリ | 131,564 KB |
実行使用メモリ | 14,212 KB |
最終ジャッジ日時 | 2024-06-22 08:45:27 |
合計ジャッジ時間 | 6,332 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 78 ms
13,244 KB |
testcase_05 | AC | 75 ms
12,964 KB |
testcase_06 | AC | 79 ms
13,120 KB |
testcase_07 | AC | 71 ms
14,164 KB |
testcase_08 | AC | 64 ms
9,828 KB |
testcase_09 | AC | 67 ms
10,100 KB |
testcase_10 | AC | 52 ms
11,936 KB |
testcase_11 | AC | 60 ms
10,048 KB |
testcase_12 | AC | 57 ms
11,532 KB |
testcase_13 | AC | 64 ms
10,292 KB |
testcase_14 | AC | 54 ms
12,240 KB |
testcase_15 | AC | 57 ms
11,984 KB |
testcase_16 | AC | 57 ms
12,296 KB |
testcase_17 | AC | 55 ms
11,616 KB |
testcase_18 | AC | 79 ms
14,212 KB |
testcase_19 | AC | 58 ms
11,580 KB |
testcase_20 | AC | 63 ms
12,372 KB |
testcase_21 | AC | 48 ms
11,660 KB |
testcase_22 | AC | 48 ms
13,824 KB |
testcase_23 | AC | 50 ms
13,696 KB |
testcase_24 | AC | 48 ms
13,656 KB |
testcase_25 | AC | 79 ms
13,452 KB |
testcase_26 | AC | 81 ms
13,480 KB |
testcase_27 | AC | 79 ms
13,444 KB |
testcase_28 | AC | 79 ms
13,524 KB |
testcase_29 | AC | 79 ms
13,636 KB |
testcase_30 | AC | 80 ms
13,420 KB |
testcase_31 | AC | 88 ms
13,548 KB |
testcase_32 | AC | 84 ms
13,528 KB |
testcase_33 | AC | 87 ms
13,484 KB |
testcase_34 | AC | 95 ms
13,880 KB |
testcase_35 | AC | 88 ms
13,544 KB |
testcase_36 | AC | 90 ms
13,652 KB |
testcase_37 | AC | 52 ms
13,820 KB |
testcase_38 | AC | 64 ms
10,408 KB |
testcase_39 | AC | 59 ms
9,680 KB |
testcase_40 | AC | 49 ms
13,532 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)); } void bAdd(T)(T[] bit, int pos, T val) in { assert(0 <= pos && pos < bit.length, "bAdd: 0 <= pos < |bit| must hold"); } do { for (int x = pos; x < bit.length; x |= x + 1) { bit[x] += val; } } // sum of [0, pos) T bSum(T)(T[] bit, int pos) in { assert(0 <= pos && pos <= bit.length, "bSum: 0 <= pos <= |bit| must hold"); } do { T ret = 0; for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) { ret += bit[x]; } return ret; } void main() { try { for (; ; ) { const N = readInt(); auto A = new long[N]; foreach (i; 0 .. N) { A[i] = readLong(); } auto B = new long[N]; foreach (i; 0 .. N) { B[i] = readLong(); } bool ok = true; ok = ok && (A[0] == B[0]); ok = ok && (A[N - 1] == B[N - 1]); alias Entry = Tuple!(long, "d", int, "i"); auto esA = new Entry[N - 1]; auto esB = new Entry[N - 1]; foreach (i; 0 .. N - 1) { esA[i] = Entry(A[i] ^ A[i + 1], i); esB[i] = Entry(B[i] ^ B[i + 1], i); } esA.sort; esB.sort; debug { writeln("esA = ", esA); writeln("esB = ", esB); } foreach (j; 0 .. N - 1) { ok = ok && (esA[j].d == esB[j].d); } if (ok) { auto vals = new int[N - 1]; foreach (j; 0 .. N - 1) { vals[esA[j].i] = esB[j].i; } long ans; auto bit = new long[N - 1]; foreach (i; 0 .. N - 1) { ans += i - bit.bSum(vals[i]); bit.bAdd(vals[i], +1); } writeln(ans); } else { writeln(-1); } } } catch (EOFException e) { } }