結果
問題 | No.2254 Reverse Only |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-03-24 23:56:59 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,766 bytes |
コンパイル時間 | 931 ms |
コンパイル使用メモリ | 128,640 KB |
実行使用メモリ | 24,336 KB |
最終ジャッジ日時 | 2024-06-22 17:42:19 |
合計ジャッジ時間 | 6,775 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 206 ms
20,940 KB |
testcase_09 | WA | - |
testcase_10 | AC | 61 ms
17,016 KB |
testcase_11 | WA | - |
testcase_12 | AC | 64 ms
16,844 KB |
testcase_13 | AC | 63 ms
16,872 KB |
testcase_14 | AC | 62 ms
16,996 KB |
testcase_15 | AC | 63 ms
20,540 KB |
testcase_16 | AC | 199 ms
23,660 KB |
testcase_17 | AC | 201 ms
24,336 KB |
testcase_18 | AC | 198 ms
23,424 KB |
testcase_19 | AC | 207 ms
24,272 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 146 ms
24,212 KB |
testcase_25 | AC | 152 ms
23,668 KB |
testcase_26 | AC | 153 ms
23,968 KB |
testcase_27 | AC | 3 ms
6,944 KB |
testcase_28 | AC | 42 ms
6,944 KB |
testcase_29 | AC | 29 ms
9,952 KB |
testcase_30 | AC | 79 ms
10,288 KB |
testcase_31 | AC | 14 ms
6,940 KB |
testcase_32 | AC | 16 ms
6,940 KB |
testcase_33 | AC | 8 ms
6,940 KB |
testcase_34 | AC | 36 ms
9,280 KB |
testcase_35 | AC | 25 ms
8,096 KB |
testcase_36 | AC | 170 ms
22,328 KB |
testcase_37 | AC | 179 ms
22,172 KB |
testcase_38 | AC | 12 ms
6,940 KB |
testcase_39 | AC | 155 ms
11,004 KB |
testcase_40 | AC | 3 ms
6,944 KB |
testcase_41 | AC | 20 ms
6,944 KB |
testcase_42 | AC | 12 ms
6,944 KB |
testcase_43 | AC | 39 ms
9,496 KB |
testcase_44 | AC | 59 ms
19,764 KB |
testcase_45 | AC | 114 ms
13,248 KB |
testcase_46 | AC | 3 ms
6,940 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 (K % 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) { } }