結果
問題 | No.2986 Permutation Puzzle |
ユーザー | titia |
提出日時 | 2024-12-13 04:59:47 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,437 bytes |
コンパイル時間 | 769 ms |
コンパイル使用メモリ | 81,536 KB |
実行使用メモリ | 1,700,584 KB |
最終ジャッジ日時 | 2024-12-13 05:01:14 |
合計ジャッジ時間 | 85,400 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
64,256 KB |
testcase_01 | MLE | - |
testcase_02 | AC | 128 ms
86,400 KB |
testcase_03 | MLE | - |
testcase_04 | AC | 101 ms
64,000 KB |
testcase_05 | MLE | - |
testcase_06 | AC | 60 ms
71,040 KB |
testcase_07 | MLE | - |
testcase_08 | AC | 162 ms
84,864 KB |
testcase_09 | MLE | - |
testcase_10 | AC | 111 ms
85,760 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 304 ms
124,800 KB |
testcase_13 | MLE | - |
testcase_14 | AC | 509 ms
225,920 KB |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | AC | 1,284 ms
423,092 KB |
testcase_19 | MLE | - |
testcase_20 | AC | 1,397 ms
463,060 KB |
testcase_21 | MLE | - |
testcase_22 | AC | 116 ms
82,688 KB |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | TLE | - |
testcase_26 | MLE | - |
testcase_27 | TLE | - |
testcase_28 | MLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
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)] flag=0 for i in range(4): if flag: break #print(i,len(Q)) NQ=[] while Q: A=Q.pop() if tuple(A)==tuple(B): flag=1 break 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)