結果

問題 No.1779 Magical Swap
ユーザー WizistWizist
提出日時 2021-12-12 22:27:31
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 751 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 87,348 KB
実行使用メモリ 126,016 KB
最終ジャッジ日時 2023-09-28 16:06:36
合計ジャッジ時間 6,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
77,092 KB
testcase_01 RE -
testcase_02 AC 264 ms
79,960 KB
testcase_03 WA -
testcase_04 AC 188 ms
126,016 KB
testcase_05 AC 118 ms
88,640 KB
testcase_06 AC 120 ms
89,548 KB
testcase_07 AC 158 ms
111,620 KB
testcase_08 AC 94 ms
77,636 KB
testcase_09 AC 113 ms
82,376 KB
testcase_10 AC 191 ms
116,416 KB
testcase_11 AC 136 ms
91,228 KB
testcase_12 AC 110 ms
81,120 KB
testcase_13 AC 153 ms
98,348 KB
testcase_14 AC 185 ms
119,008 KB
testcase_15 AC 468 ms
79,772 KB
testcase_16 AC 139 ms
94,300 KB
testcase_17 WA -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[x]; a2 = c2[x]
			if len(a1) != len(a2): return False
			a1.sort(); a2.sort()
			if a1[0] * a2[-1] > n and a1[-1] * a2[0] > n: return False
		return True

	print("Yes" if check() else "No")
0