結果

問題 No.1779 Magical Swap
ユーザー ああああ
提出日時 2023-01-16 12:05:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 128,584 KB
最終ジャッジ日時 2023-08-29 00:34:47
合計ジャッジ時間 5,171 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,604 KB
testcase_01 AC 98 ms
71,448 KB
testcase_02 AC 205 ms
78,636 KB
testcase_03 AC 109 ms
78,000 KB
testcase_04 AC 135 ms
102,636 KB
testcase_05 AC 115 ms
85,712 KB
testcase_06 AC 116 ms
87,084 KB
testcase_07 AC 130 ms
99,168 KB
testcase_08 AC 100 ms
77,024 KB
testcase_09 AC 133 ms
85,368 KB
testcase_10 AC 212 ms
112,332 KB
testcase_11 AC 164 ms
103,224 KB
testcase_12 AC 127 ms
80,820 KB
testcase_13 AC 194 ms
117,948 KB
testcase_14 AC 218 ms
128,584 KB
testcase_15 AC 486 ms
79,324 KB
testcase_16 AC 143 ms
106,912 KB
testcase_17 AC 219 ms
79,188 KB
testcase_18 AC 97 ms
71,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
T=int(input())

for _ in range(T):
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    if A[0]!=B[0]:
        print("No")
        continue
    dict_A=defaultdict(int)
    dict_B=defaultdict(int)
    ans="Yes"
    check=[False]*(N+1)
    for i in range(2,N+1):
        if check[i]:
            continue
        if 2*i>N:
            if A[i-1]!=B[i-1]:
                ans="No"
            continue
        for j in range(i,N+1,i):
            if check[j]:
                continue
            check[j]=True
            dict_A[A[j-1]]+=1
            dict_B[B[j-1]]+=1
    for k in dict_A.keys():
        if dict_A[k]!=dict_B[k]:
            ans="No"
            break
    print(ans)
0