Contest Duration: - (local time) (120 minutes) Back to Home

Submission #9422077

Source Code Expand

Copy
import sys

import itertools
from collections import deque

A = list(map(lambda x: int(x) - 1,read().split())) + [-1]

def test(A,B):
for x,y in zip(B, B[1:]):
if A[x] == y:
return False
return True

def solve_small(cand, A, ng_first = -1):
for p in itertools.permutations(cand):
if p[0] == ng_first:
continue
if test(A, p):
return p
return False

if N <= 4:
p = solve_small(range(N), A)
if not p:
print(-1)
exit()
print(' '.join(str(x+1) for x in p))
exit()

rest = deque(range(N))
B = []
prev = N
for _ in range(N-4):
x = rest[0]; y = rest[1]
if A[prev] == x:
B.append(y)
rest.popleft()
rest.popleft()
rest.appendleft(x)
else:
B.append(x)
rest.popleft()
prev = B[-1]

B += list(solve_small(rest, A, A[B[-1]]))

print(' '.join(str(x+1) for x in B))

#### Submission Info

Submission Time 2020-01-11 20:26:22+0900 D - Arrangement maspy Python (3.4.3) 0 1096 Byte RE 140 ms 18384 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
 AC × 3
 AC × 35 RE × 15
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All hand2_01, hand2_02, hand2_03, hand2_04, hand_01, hand_02, hand_03, hand_04, handmaid_01, max_01, max_02, max_03, max_04, max_05, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, sample_01, sample_02, sample_03, small_01, small_02, small_03, small_04, small_05, special2_01, special2_02, special2_03, special2_04, special2_05, special2_06, special2_07, special2_08, special2_09, special2_10, special_01, special_02, special_03
Case Name Status Exec Time Memory
hand2_01 AC 55 ms 3444 KB
hand2_02 AC 20 ms 3316 KB
hand2_03 RE 101 ms 12632 KB
hand2_04 RE 101 ms 12696 KB
hand_01 AC 20 ms 3316 KB
hand_02 AC 20 ms 3316 KB
hand_03 AC 128 ms 18384 KB
hand_04 AC 128 ms 18340 KB
handmaid_01 AC 20 ms 3316 KB
max_01 AC 137 ms 18340 KB
max_02 AC 137 ms 18336 KB
max_03 AC 140 ms 18384 KB
max_04 AC 133 ms 18340 KB
max_05 AC 127 ms 18384 KB
random_01 AC 20 ms 3316 KB
random_02 AC 20 ms 3316 KB
random_03 AC 20 ms 3316 KB
random_04 AC 20 ms 3316 KB
random_05 AC 20 ms 3316 KB
random_06 AC 20 ms 3316 KB
random_07 AC 20 ms 3316 KB
random_08 AC 20 ms 3316 KB
random_09 AC 20 ms 3316 KB
random_10 AC 20 ms 3316 KB
random_11 AC 20 ms 3316 KB
random_12 AC 20 ms 3316 KB
random_13 AC 20 ms 3316 KB
random_14 AC 20 ms 3316 KB
random_15 AC 20 ms 3316 KB
sample_01 AC 20 ms 3316 KB
sample_02 AC 20 ms 3316 KB
sample_03 AC 20 ms 3316 KB
small_01 AC 20 ms 3316 KB
small_02 AC 20 ms 3316 KB
small_03 AC 20 ms 3316 KB
small_04 AC 20 ms 3316 KB
small_05 AC 20 ms 3316 KB
special2_01 RE 107 ms 12632 KB
special2_02 RE 108 ms 12760 KB
special2_03 RE 109 ms 12632 KB
special2_04 RE 108 ms 12760 KB
special2_05 RE 102 ms 12632 KB
special2_06 RE 110 ms 12760 KB
special2_07 RE 114 ms 12760 KB
special2_08 RE 110 ms 12760 KB
special2_09 RE 111 ms 12632 KB
special2_10 RE 106 ms 12632 KB
special_01 RE 20 ms 3316 KB
special_02 RE 25 ms 3948 KB
special_03 RE 118 ms 12048 KB