QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124240#5665. AA Country and King DreamoonbakuganulitWA 0ms8156kbPython3866b2023-07-14 14:47:372023-07-14 14:47:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 14:47:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8156kb
  • [2023-07-14 14:47:37]
  • 提交

answer

def solve():
    n = int(input())
    path = list(map(int, input().split()))

    path[-1] = 1
    path[0] = 1

    available = set(range(1, n + 1))
    zeros = path.count(0)
    last_city_index = path.index(0) - 1
    last_city = path[last_city_index]

    if zeros % 2 == 0:
        if last_city > path[last_city_index + 2]:
            missing_path = [path[last_city_index + 2] 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)]

    ans = [x if x != 0 else missing_path.pop() for x in path]
    print(" ".join(map(str, 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: 0
Wrong Answer
time: 0ms
memory: 8156kb

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 1 2 1 5 1
1 2 3 1 0 2 1 5 1
1 2 2 2 1 2 1 5 1
1 2 2 0 1 0 1 5 1
1 3 1 2 1 1 1 5 1
1 3 0 2 0 1 0 5 1
1 4 1 3 1 2 1 1 1
1 4 1 3 1 2 1 1 1
1 4 1 3 1 2 1 1 1

result:

wrong answer 1st lines differ - expected: '1 2 3 2 4 2 1 5 1', found: '1 2 3 2 1 2 1 5 1'