結果
問題 | No.2254 Reverse Only |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-03-24 23:56:14 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,766 bytes |
コンパイル時間 | 895 ms |
コンパイル使用メモリ | 128,852 KB |
実行使用メモリ | 24,768 KB |
最終ジャッジ日時 | 2024-06-22 17:41:51 |
合計ジャッジ時間 | 7,071 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 181 ms
24,228 KB |
testcase_09 | WA | - |
testcase_10 | AC | 53 ms
18,140 KB |
testcase_11 | WA | - |
testcase_12 | AC | 54 ms
18,680 KB |
testcase_13 | AC | 54 ms
19,128 KB |
testcase_14 | AC | 54 ms
19,516 KB |
testcase_15 | AC | 56 ms
20,448 KB |
testcase_16 | AC | 180 ms
24,704 KB |
testcase_17 | AC | 182 ms
23,220 KB |
testcase_18 | AC | 177 ms
23,460 KB |
testcase_19 | AC | 183 ms
24,312 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 131 ms
23,304 KB |
testcase_25 | AC | 137 ms
23,400 KB |
testcase_26 | AC | 137 ms
24,192 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 38 ms
6,940 KB |
testcase_29 | AC | 26 ms
9,260 KB |
testcase_30 | AC | 74 ms
10,080 KB |
testcase_31 | AC | 13 ms
6,944 KB |
testcase_32 | AC | 14 ms
6,944 KB |
testcase_33 | AC | 7 ms
6,940 KB |
testcase_34 | AC | 31 ms
9,244 KB |
testcase_35 | AC | 21 ms
8,016 KB |
testcase_36 | AC | 153 ms
21,540 KB |
testcase_37 | AC | 164 ms
21,724 KB |
testcase_38 | AC | 10 ms
6,940 KB |
testcase_39 | AC | 142 ms
11,024 KB |
testcase_40 | AC | 3 ms
6,940 KB |
testcase_41 | AC | 18 ms
6,944 KB |
testcase_42 | AC | 11 ms
6,944 KB |
testcase_43 | AC | 35 ms
9,440 KB |
testcase_44 | AC | 52 ms
18,088 KB |
testcase_45 | AC | 102 ms
12,960 KB |
testcase_46 | AC | 2 ms
6,944 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; } 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)); } int root(int[] uf, int u) { return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u])); } bool connect(int[] uf, int u, int v) { u = uf.root(u); v = uf.root(v); if (u == v) return false; if (uf[u] > uf[v]) swap(u, v); uf[u] += uf[v]; uf[v] = u; return true; } int N, K; int[] A, B; bool solve() { if (A == B) { return true; } if (K == 1) { return false; } else if (K == N) { auto revA = A.dup.reverse; if (revA == B) return true; return false; } else if (K > N) { return false; } else { alias Entry = Tuple!(int, "val", int, "pos"); auto as = new Entry[N]; auto bs = new Entry[N]; foreach (i; 0 .. N) as[i] = Entry(A[i], i); foreach (i; 0 .. N) bs[i] = Entry(B[i], i); as.sort; bs.sort; auto ps = new int[N]; foreach (i; 0 .. N) { if (as[i].val != bs[i].val) { return false; } ps[as[i].pos] = bs[i].pos; } if (N % 2 == 0) { return true; } foreach (i; 0 .. N - 1) { if (as[i].val == as[i + 1].val) { return true; } } auto uf = new int[N]; uf[] = -1; foreach (i; 0 .. N) { uf.connect(i, ps[i]); } int numComps; foreach (i; 0 .. N) if (uf[i] < 0) { ++numComps; } if ((N - numComps) % 2 == 0) { return true; } return false; } } void main() { try { for (; ; ) { N = readInt; K = readInt; A = new int[N]; foreach (i; 0 .. N) A[i] = readInt; B = new int[N]; foreach (i; 0 .. N) B[i] = readInt; const ans = solve; writeln(ans ? "Yes" : "No"); } } catch (EOFException e) { } }