QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86597#4800. Oscar's Round Must Have a Constructive ProblemmthanekaTL 13ms8092kbPython3638b2023-03-10 11:19:572023-03-10 11:20:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 11:20:00]
  • 评测
  • 测评结果:TL
  • 用时:13ms
  • 内存:8092kb
  • [2023-03-10 11:19:57]
  • 提交

answer

def r(l: list, A: list, used: set):
   n = len(A)
   if len(used) == n:
      return l

   i = len(l)
   for num in range(1, n + 1):
      if num != A[i] and num not in used:
         l.append(num)
         used.add(num)

         result = r(l, A, used)
         if result:
            return result

         l.pop()
         used.remove(num)
   
   return False



T = int(input())
for _ in range(T):
   n = int(input())
   A = list(map(int, input().split()))
   used = set()

   result = r([], A, used)
   if result:
      print("YES")
      print(' '.join(map(str, result)))
   else:
      print("NO")

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 8092kb

input:

3
3
3 3 3
3
3 2 1
6
1 1 4 5 1 4

output:

NO
YES
1 3 2
YES
2 3 1 4 5 6

result:

ok ok

Test #2:

score: -100
Time Limit Exceeded

input:

50069
1
1
2
1 1
2
1 2
2
2 1
2
2 2
3
1 1 1
3
1 1 2
3
1 1 3
3
1 2 1
3
1 2 2
3
1 2 3
3
1 3 1
3
1 3 2
3
1 3 3
3
2 1 1
3
2 1 2
3
2 1 3
3
2 2 1
3
2 2 2
3
2 2 3
3
2 3 1
3
2 3 2
3
2 3 3
3
3 1 1
3
3 1 2
3
3 1 3
3
3 2 1
3
3 2 2
3
3 2 3
3
3 3 1
3
3 3 2
3
3 3 3
4
1 1 1 1
4
1 1 1 2
4
1 1 1 3
4
1 1 1 4
4
1 1 2 1
...

output:

NO
NO
YES
2 1
YES
1 2
NO
NO
YES
2 3 1
YES
2 3 1
YES
2 1 3
YES
2 1 3
YES
2 3 1
YES
2 1 3
YES
2 1 3
YES
3 1 2
YES
1 2 3
YES
1 2 3
YES
1 3 2
YES
1 3 2
NO
YES
1 3 2
YES
1 2 3
YES
1 2 3
YES
3 1 2
YES
1 2 3
YES
1 2 3
YES
1 3 2
YES
1 3 2
YES
2 1 3
YES
1 3 2
YES
1 2 3
YES
1 2 3
NO
NO
YES
2 3 4 1
YES
2 3 4 1...

result: