QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124261 | #5665. AA Country and King Dreamoon | bakuganulit | RE | 13ms | 8152kb | Python3 | 1.2kb | 2023-07-14 15:13:49 | 2023-07-14 15:13:52 |
Judging History
answer
def solve():
n = int(input())
path = list(map(int, input().split()))
path[-1] = 1
path[0] = 1
available = set(range(1, n + 1))
for num in path:
if num in available:
available.remove(num)
zeros = path.count(0)
last_city_index = path.index(0) - 1
last_city = path[last_city_index]
if zeros % 2 == 0:
next_city = path[last_city_index + zeros +
1] if (last_city_index + zeros) <= len(path) else 0
if last_city > next_city:
missing_path = [next_city if i %
2 == 0 else available.pop() for i in range(zeros)]
else:
missing_path = [available.pop() if i %
2 == 0 else last_city for i in range(zeros)]
else:
missing_path = [available.pop() if i % 2 == 0 else last_city
for i in range(zeros)]
missing_path = missing_path[::-1]
ans = [x if x != 0 else missing_path.pop() for x in path]
print(" ".join(str(num) for num in ans))
if __name__ == "__main__":
t = int(input())
for _ in range(t):
solve()
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 8152kb
input:
9 5 1 2 3 2 0 2 1 5 1 5 1 2 3 0 0 2 1 5 1 5 1 2 0 0 0 2 1 5 1 5 1 2 0 0 0 0 1 5 1 5 1 0 0 0 0 0 1 5 1 5 1 0 0 0 0 0 0 5 1 5 1 0 0 0 0 0 0 0 1 5 1 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0
output:
1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1
result:
ok 9 lines
Test #2:
score: -100
Runtime Error
input:
28668 2 0 2 1 2 0 0 1 2 0 0 0 2 1 0 1 2 1 0 0 2 1 2 0 3 0 2 1 3 1 3 0 0 1 3 1 3 0 0 0 3 1 3 0 0 0 0 1 3 0 0 0 0 0 3 1 0 1 3 1 3 1 0 0 3 1 3 1 0 0 0 1 3 1 0 0 0 0 3 1 2 0 3 1 3 1 2 0 0 1 3 1 2 0 0 0 3 1 2 1 0 1 3 1 2 1 0 0 3 1 2 1 3 0 3 0 2 3 2 1 3 0 0 3 2 1 3 0 0 0 2 1 3 1 0 3 2 1 3 1 0 0 2 1 3 1 2 ...