結果
問題 | No.1779 Magical Swap |
ユーザー | Shirotsume |
提出日時 | 2021-12-08 00:19:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,604 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 81,536 KB |
実行使用メモリ | 98,560 KB |
最終ジャッジ日時 | 2024-07-08 04:07:20 |
合計ジャッジ時間 | 7,196 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
59,904 KB |
testcase_01 | WA | - |
testcase_02 | AC | 122 ms
77,952 KB |
testcase_03 | AC | 72 ms
73,728 KB |
testcase_04 | AC | 78 ms
94,336 KB |
testcase_05 | AC | 56 ms
78,720 KB |
testcase_06 | AC | 58 ms
81,536 KB |
testcase_07 | AC | 79 ms
95,488 KB |
testcase_08 | AC | 43 ms
60,928 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
ソースコード
import sys from collections import Counter input = lambda: sys.stdin.readline().rstrip() INF = 10 ** 19 from math import gcd 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 def solve(): n = int(input()) a = [0] + list(map(int,input().split())) b = [0] + list(map(int,input().split())) if a[1] != b[1]: return 'No' now = 1 ans = 'Yes' U = dsu(n + 1) for i in range(2,n + 1): for j in range(2, n + 1): if i * j // gcd(i, j) <= n: U.merge(i, j) break a_now = [[] for _ in range(n + 1)] b_now = [[] for _ in range(n + 1)] for i in range(2, n + 1): a_now[U.leader(i)].append(a[i]) b_now[U.leader(i)].append(b[i]) for i in range(n): a_now[i].sort() b_now[i].sort() if a_now[i] != b_now[i]: ans = 'No' break return ans t = int(input()) for _ in range(t): print(solve())