結果
問題 | No.2732 Similar Permutations |
ユーザー |
![]() |
提出日時 | 2024-04-19 23:03:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,230 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 82,204 KB |
実行使用メモリ | 124,160 KB |
最終ジャッジ日時 | 2024-10-11 17:11:41 |
合計ジャッジ時間 | 26,217 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 67 WA * 34 |
ソースコード
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) if N==2: x=(A[0]+1)^(A[1]+2) y=(A[0]+2)^(A[1]+1) if x==y: print(1,2) print(2,1) else: print(-1) exit() X=[[] for i in range(4)] for i in range(N): X[A[i]%4].append(i) for i in range(2): if len(X[i])>=2: k=X[i][0] l=X[i][1] ANS1=[0]*N ANS2=[0]*N ANS1[k]=1 ANS1[l]=2 ANS2[k]=2 ANS2[l]=1 now=1 LL=[1,2] for i in range(N): if ANS1[i]==0: ANS1[i]=now now+=1 while now in LL: now+=1 now=1 for i in range(N): if ANS2[i]==0: ANS2[i]=now now+=1 while now in LL: now+=1 print(*ANS1) print(*ANS2) exit() from itertools import permutations from collections import Counter if N<=8: L=list(permutations(range(N))) ANS=[0]*len(L) for i in range(len(L)): xor=0 for j in range(N): xor^=A[j]+L[i][j] ANS[i]=xor C=Counter(ANS) ans=-1 for c in C: if C[c]>=2: ans=c break if ans==-1: print(ans) exit() IND=[] for i in range(len(L)): if ANS[i]==ans: IND.append(i) AA=[0]*N for i in range(N): AA[i]=L[IND[0]][i]+1 print(*AA) AA=[0]*N for i in range(N): AA[i]=L[IND[1]][i]+1 print(*AA) exit() B=[(A[i],i) for i in range(N)] B.sort() IND=[] for i in range(N-1): if B[i+1][0]<=N: IND=[B[i][1],B[i+1][1]] LL=[B[i][0],B[i+1][0]] break k,l=IND ANS1=[0]*N ANS2=[0]*N if LL[0]==LL[1]: ANS1[k]=1 ANS1[l]=2 ANS2[k]=2 ANS2[l]=1 LL=[1,2] else: ANS1[k]=LL[0] ANS1[l]=LL[1] ANS2[k]=LL[1] ANS2[l]=LL[0] now=1 for i in range(N): if ANS1[i]==0: ANS1[i]=now now+=1 while now in LL: now+=1 now=1 for i in range(N): if ANS2[i]==0: ANS2[i]=now now+=1 while now in LL: now+=1 print(*ANS1) print(*ANS2)