結果
問題 | No.1779 Magical Swap |
ユーザー | rlangevin |
提出日時 | 2023-03-15 08:59:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 305 ms / 2,000 ms |
コード長 | 1,479 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 81,588 KB |
実行使用メモリ | 133,348 KB |
最終ジャッジ日時 | 2023-10-18 12:14:56 |
合計ジャッジ時間 | 5,125 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,468 KB |
testcase_01 | AC | 44 ms
55,468 KB |
testcase_02 | AC | 182 ms
77,876 KB |
testcase_03 | AC | 109 ms
77,164 KB |
testcase_04 | AC | 196 ms
115,784 KB |
testcase_05 | AC | 135 ms
92,460 KB |
testcase_06 | AC | 140 ms
94,128 KB |
testcase_07 | AC | 184 ms
110,084 KB |
testcase_08 | AC | 83 ms
76,984 KB |
testcase_09 | AC | 127 ms
87,188 KB |
testcase_10 | AC | 240 ms
129,780 KB |
testcase_11 | AC | 157 ms
98,844 KB |
testcase_12 | AC | 108 ms
79,768 KB |
testcase_13 | AC | 207 ms
117,312 KB |
testcase_14 | AC | 251 ms
133,348 KB |
testcase_15 | AC | 305 ms
78,864 KB |
testcase_16 | AC | 186 ms
103,860 KB |
testcase_17 | AC | 196 ms
77,420 KB |
testcase_18 | AC | 42 ms
55,496 KB |
ソースコード
import sys readline = sys.stdin.readline from collections import * class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] T = int(readline()) for _ in range(T): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) U = UnionFind(N+1) for i in range(2, N+1): for j in range(2 * i, N+1, i): U.union(i, j) D1 = [defaultdict(int) for i in range(N+1)] D2 = [defaultdict(int) for i in range(N+1)] for i in range(1, N + 1): D1[U.find(i)][A[i-1]] += 1 D2[U.find(i)][B[i-1]] += 1 for i in range(N+1): if D1[i] != D2[i]: print("No") break else: print("Yes")