結果
問題 | No.2986 Permutation Puzzle |
ユーザー | titia |
提出日時 | 2024-12-13 04:55:48 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,404 bytes |
コンパイル時間 | 368 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 1,658,900 KB |
最終ジャッジ日時 | 2024-12-13 04:57:34 |
合計ジャッジ時間 | 92,282 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
83,220 KB |
testcase_01 | MLE | - |
testcase_02 | AC | 550 ms
229,888 KB |
testcase_03 | MLE | - |
testcase_04 | AC | 91 ms
83,412 KB |
testcase_05 | MLE | - |
testcase_06 | AC | 84 ms
83,232 KB |
testcase_07 | MLE | - |
testcase_08 | AC | 148 ms
88,696 KB |
testcase_09 | MLE | - |
testcase_10 | AC | 302 ms
139,040 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 269 ms
126,244 KB |
testcase_13 | MLE | - |
testcase_14 | AC | 528 ms
237,100 KB |
testcase_15 | MLE | - |
testcase_16 | AC | 1,313 ms
433,904 KB |
testcase_17 | MLE | - |
testcase_18 | AC | 1,305 ms
425,464 KB |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | TLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | TLE | - |
testcase_34 | MLE | - |
testcase_35 | TLE | - |
testcase_36 | MLE | - |
testcase_37 | MLE | - |
testcase_38 | TLE | - |
testcase_39 | MLE | - |
testcase_40 | TLE | - |
testcase_41 | MLE | - |
testcase_42 | TLE | - |
testcase_43 | MLE | - |
ソースコード
def change(A,com,ind): if com=="R": A2=[] for i in range(N): A2.append(A[i*N:i*N+N]) C=[[] for i in range(N)] for j in range(N): C[A2[ind-1][j]-1]=A2[j] D=[] for i in range(N): for x in C[i]: D.append(x) return D else: B=[] for i in range(N): for j in range(N): B.append(A[j*N+i]) #print(B) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) C=[[] for i in range(N)] for j in range(N): C[B2[ind-1][j]-1]=B2[j] D=[] for i in range(N): for x in C[i]: D.append(x) E=[] for i in range(N): for j in range(N): E.append(D[j*N+i]) return E N,K=map(int,input().split()) A=[] for i in range(N): A+=list(map(int,input().split())) A0=tuple(A) B=[] for i in range(N): B+=list(map(int,input().split())) DICT=dict() DICT[tuple(A)]=[] FROM=dict() Q=[tuple(A)] for i in range(4): #print(i,len(Q)) NQ=[] while Q: A=Q.pop() ANS=DICT[A] for ind in range(1,N+1): A2=change(A,"R",ind) if tuple(A2) in DICT: pass else: ANS2=ANS+[["R",ind]] DICT[tuple(A2)]=ANS2 FROM[tuple(A2)]=(tuple(A),"R",ind) NQ.append(tuple(A2)) A2=change(A,"C",ind) if tuple(A2) in DICT: pass else: ANS2=ANS+[["R",ind]] DICT[tuple(A2)]=ANS2 FROM[tuple(A2)]=(tuple(A),"C",ind) NQ.append(tuple(A2)) Q=NQ B=tuple(B) ANS=[] while B!=tuple(A0): #print("!!",B) fr,com,ind=FROM[B] #print(B,fr,com,ind) if com=="R": fr2=[] for i in range(N): fr2.append(fr[i*N:i*N+N]) need=fr2[ind-1] #print(need) while tuple(B)!=tuple(fr): #print(B) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) #print(B2) for i in range(N): if B2[i]==tuple(need): ANS.append(("R",i+1)) B=change(B,"R",i+1) break B=tuple(B) B=tuple(B) else: B2=[] for i in range(N): for j in range(N): B2.append(B[j*N+i]) fr2=[] for i in range(N): for j in range(N): fr2.append(fr[j*N+i]) B=B2 fr=fr2 fr2=[] for i in range(N): fr2.append(fr[i*N:i*N+N]) need=fr2[ind-1] while tuple(B)!=tuple(fr): #print(B,need) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) for i in range(N): if B2[i]==tuple(need): ANS.append(("C",i+1)) B=change(B,"R",i+1) break B=tuple(B) B2=[] for i in range(N): for j in range(N): B2.append(B[j*N+i]) B=tuple(B2) print(len(ANS)) for com,ind in ANS: print(com,ind)