結果

問題 No.2732 Similar Permutations
ユーザー titiatitia
提出日時 2024-04-21 01:53:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 46,840 KB
最終ジャッジ日時 2024-04-21 01:54:13
合計ジャッジ時間 37,183 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 29 ms
11,136 KB
testcase_02 AC 164 ms
21,644 KB
testcase_03 AC 294 ms
30,788 KB
testcase_04 AC 110 ms
17,128 KB
testcase_05 AC 87 ms
15,872 KB
testcase_06 AC 53 ms
13,056 KB
testcase_07 AC 220 ms
25,992 KB
testcase_08 AC 125 ms
18,412 KB
testcase_09 AC 70 ms
14,396 KB
testcase_10 AC 503 ms
45,324 KB
testcase_11 AC 63 ms
13,568 KB
testcase_12 AC 470 ms
45,688 KB
testcase_13 AC 515 ms
45,508 KB
testcase_14 AC 476 ms
45,788 KB
testcase_15 AC 475 ms
46,536 KB
testcase_16 AC 366 ms
37,056 KB
testcase_17 AC 362 ms
35,376 KB
testcase_18 AC 467 ms
42,732 KB
testcase_19 AC 501 ms
46,776 KB
testcase_20 AC 505 ms
45,636 KB
testcase_21 AC 487 ms
45,512 KB
testcase_22 AC 277 ms
30,448 KB
testcase_23 AC 501 ms
45,404 KB
testcase_24 AC 289 ms
30,972 KB
testcase_25 AC 500 ms
45,404 KB
testcase_26 AC 410 ms
39,436 KB
testcase_27 AC 504 ms
45,528 KB
testcase_28 AC 365 ms
37,840 KB
testcase_29 AC 486 ms
45,384 KB
testcase_30 AC 336 ms
35,500 KB
testcase_31 AC 471 ms
45,384 KB
testcase_32 AC 429 ms
42,836 KB
testcase_33 AC 479 ms
45,512 KB
testcase_34 AC 322 ms
33,432 KB
testcase_35 AC 474 ms
45,464 KB
testcase_36 AC 461 ms
42,760 KB
testcase_37 AC 472 ms
45,360 KB
testcase_38 AC 432 ms
40,884 KB
testcase_39 AC 460 ms
45,492 KB
testcase_40 AC 435 ms
39,480 KB
testcase_41 AC 477 ms
45,268 KB
testcase_42 AC 389 ms
36,588 KB
testcase_43 AC 479 ms
45,020 KB
testcase_44 AC 253 ms
28,788 KB
testcase_45 AC 454 ms
44,960 KB
testcase_46 AC 419 ms
41,576 KB
testcase_47 AC 464 ms
44,556 KB
testcase_48 AC 291 ms
31,388 KB
testcase_49 AC 486 ms
43,888 KB
testcase_50 AC 282 ms
30,728 KB
testcase_51 AC 503 ms
42,260 KB
testcase_52 AC 434 ms
37,624 KB
testcase_53 AC 527 ms
46,252 KB
testcase_54 AC 551 ms
46,840 KB
testcase_55 AC 548 ms
46,264 KB
testcase_56 AC 489 ms
46,256 KB
testcase_57 AC 283 ms
29,388 KB
testcase_58 AC 339 ms
36,092 KB
testcase_59 AC 331 ms
34,460 KB
testcase_60 AC 304 ms
30,644 KB
testcase_61 AC 251 ms
28,860 KB
testcase_62 AC 397 ms
40,244 KB
testcase_63 AC 28 ms
11,008 KB
testcase_64 AC 31 ms
11,008 KB
testcase_65 AC 26 ms
11,136 KB
testcase_66 AC 27 ms
11,136 KB
testcase_67 AC 26 ms
11,008 KB
testcase_68 AC 28 ms
11,008 KB
testcase_69 AC 29 ms
11,136 KB
testcase_70 AC 27 ms
11,136 KB
testcase_71 AC 28 ms
11,008 KB
testcase_72 AC 28 ms
11,136 KB
testcase_73 AC 27 ms
11,008 KB
testcase_74 AC 28 ms
11,008 KB
testcase_75 AC 27 ms
11,008 KB
testcase_76 AC 26 ms
11,008 KB
testcase_77 AC 28 ms
11,008 KB
testcase_78 AC 27 ms
11,008 KB
testcase_79 AC 29 ms
11,008 KB
testcase_80 AC 28 ms
11,136 KB
testcase_81 AC 27 ms
11,008 KB
testcase_82 AC 28 ms
11,136 KB
testcase_83 AC 30 ms
11,008 KB
testcase_84 AC 26 ms
11,008 KB
testcase_85 AC 28 ms
11,136 KB
testcase_86 AC 27 ms
11,136 KB
testcase_87 AC 28 ms
11,008 KB
testcase_88 AC 28 ms
11,136 KB
testcase_89 AC 28 ms
11,136 KB
testcase_90 AC 28 ms
11,136 KB
testcase_91 AC 28 ms
11,136 KB
testcase_92 AC 26 ms
11,136 KB
testcase_93 AC 26 ms
11,136 KB
testcase_94 AC 27 ms
11,136 KB
testcase_95 AC 26 ms
11,136 KB
testcase_96 AC 26 ms
11,008 KB
testcase_97 AC 27 ms
11,008 KB
testcase_98 AC 29 ms
11,136 KB
testcase_99 AC 27 ms
11,136 KB
testcase_100 AC 27 ms
11,008 KB
testcase_101 AC 27 ms
11,136 KB
testcase_102 AC 28 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

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