結果
問題 | No.1779 Magical Swap |
ユーザー | Wizist |
提出日時 | 2021-12-12 22:43:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 878 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 86,960 KB |
実行使用メモリ | 125,688 KB |
最終ジャッジ日時 | 2023-09-28 16:26:08 |
合計ジャッジ時間 | 5,548 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
77,128 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 105 ms
77,992 KB |
testcase_04 | AC | 191 ms
125,688 KB |
testcase_05 | AC | 118 ms
88,400 KB |
testcase_06 | AC | 123 ms
89,248 KB |
testcase_07 | AC | 157 ms
111,492 KB |
testcase_08 | AC | 94 ms
77,516 KB |
testcase_09 | AC | 121 ms
82,364 KB |
testcase_10 | AC | 194 ms
116,804 KB |
testcase_11 | AC | 145 ms
91,192 KB |
testcase_12 | AC | 117 ms
81,132 KB |
testcase_13 | AC | 181 ms
109,360 KB |
testcase_14 | AC | 191 ms
119,256 KB |
testcase_15 | AC | 488 ms
79,616 KB |
testcase_16 | AC | 141 ms
94,056 KB |
testcase_17 | AC | 182 ms
78,996 KB |
testcase_18 | AC | 87 ms
77,096 KB |
ソースコード
#!/usr/bin/env python3 # # No.1779 Magical Swap # import math N = 100001 fp = [0] * N for i in range(2, len(fp)): if fp[i] == 0: fp[i] = i for j in range(i * i, len(fp), i): if fp[j] == 0: fp[j] = i def lcm(x, y): return x * y // math.gcd(x, y) ncases = int(input()) for caseno in range(ncases): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c1, c2 = {}, {} for i in range(1, len(a)): if a[i] == b[i]: continue if a[i] not in c1: c1[a[i]] = [] if b[i] not in c2: c2[b[i]] = [] c1[a[i]].append(fp[i + 1]) c2[b[i]].append(fp[i + 1]) def check(): if a[0] != b[0]: return False for x in c1: a1 = c1.get(x, []); a2 = c2.get(x, []) if len(a1) != len(a2): return False a1.sort(); a2.sort() if lcm(a[-1], 2) > n and lcm(a1[-1], 2) > n: return False return True print("Yes" if check() else "No")