結果

問題 No.2732 Similar Permutations
ユーザー titia
提出日時 2024-04-21 01:53:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 528 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 46,776 KB
最終ジャッジ日時 2024-10-13 00:21:47
合計ジャッジ時間 36,428 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 101
権限があれば一括ダウンロードができます

ソースコード

diff #

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(4):
    if i>=2 and len(X[i])>=2:
        k=X[i][0]
        l=X[i][1]

        ANS1=[0]*N
        ANS2=[0]*N

        ANS1[k]=2
        ANS1[l]=3

        ANS2[k]=3
        ANS2[l]=2

        LL=[2,3]

        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)

        exit()

    if i<=1 and len(X[i])>=2:
        k=X[i][0]
        l=X[i][1]

        ANS1=[0]*N
        ANS2=[0]*N

        ANS1[k]=2
        ANS1[l]=1

        ANS2[k]=1
        ANS2[l]=2

        LL=[1,2]

        now=3

        for i in range(N):
            if ANS1[i]==0:
                ANS1[i]=now
                now+=1

            while now in LL:
                now+=1

        now=3

        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<=5:
    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]+1)

        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)
    
    
0