結果
問題 | No.2254 Reverse Only |
ユーザー | first_vil |
提出日時 | 2023-03-24 21:54:46 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,794 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 113,152 KB |
最終ジャッジ日時 | 2024-09-18 17:03:18 |
合計ジャッジ時間 | 5,807 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,608 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | AC | 35 ms
52,480 KB |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
ソースコード
import sys int1 = lambda x: int(x) - 1 # input = lambda: sys.stdin.buffer.readline() input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) i1 = lambda: int1(input()) mi = lambda: map(int, input().split()) mi1 = lambda: map(int1, input().split()) li = lambda: list(mi()) li1 = lambda: list(mi1()) lli = lambda n: [li() for _ in range(n)] INF = float("inf") # mod = int(1e9 + 7) mod = 998244353 class dsu: n = 1 parent_or_size = [-1 for i in range(n)] def __init__(self, N): self.n = N self.parent_or_size = [-1 for i in range(N)] def merge(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [0 for i in range(self.n)] group_size = [0 for i in range(self.n)] for i in range(self.n): leader_buf[i] = self.leader(i) group_size[leader_buf[i]] += 1 result = [[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2 = [] for i in range(self.n): if len(result[i]) > 0: result2.append(result[i]) return result2 n, k = mi() a = li() b = li() if k != 3: exit(-1) if a == b: print("Yes") exit() if sorted(a) != sorted(b): print("No") exit() if k <= 2: print("Yes") exit() uf = dsu(n) for i in range(k + 1, n - 1): uf.merge(i, i + 1) uf.merge(n - 1 - i, n - 1 - (i + 1)) if k == 3: for i in range(n - 2): uf.merge(i, i + 2) sa = [list() for i in range(n)] sb = [list() for i in range(n)] for i in range(n): r = uf.leader(i) sa[r].append(a[i]) sb[r].append(b[i]) for i in range(n): if sorted(sa[i]) != sorted(sb[i]): print("No") exit() print("Yes")