fork(1) download
  1. def calculate_mex(triplet):
  2. present = set(triplet)
  3. for i in range(4):
  4. if i not in present:
  5. return i
  6. return 4
  7.  
  8. def is_easy_yes_case(arr):
  9. unique_values = set(x for x in arr if x != -1)
  10. if len(unique_values) > 1:
  11. return False
  12. if len(unique_values) == 1 and 0 in unique_values:
  13. return False
  14. return True
  15.  
  16. def is_good_array(possible_arr):
  17. n = len(possible_arr)
  18. for i in range(n - 2):
  19. triplet = possible_arr[i:i+3]
  20. if calculate_mex(triplet) != max(triplet) - min(triplet):
  21. return False
  22. return True
  23.  
  24. def can_make_good_array(arr):
  25. for replacement in range(101):
  26. filled = [replacement if x == -1 else x for x in arr]
  27. if is_good_array(filled):
  28. return True
  29. return False
  30.  
  31. def process_test_cases():
  32. t = int(input())
  33. for _ in range(t):
  34. n = int(input())
  35. arr = list(map(int, input().split()))
  36. if is_easy_yes_case(arr) or can_make_good_array(arr):
  37. print("YES")
  38. else:
  39. print("NO")
  40.  
  41. process_test_cases()
  42.  
Success #stdin #stdout 0.11s 14016KB
stdin
8
3
-1 -1 -1
5
1 1 1 1 0
6
5 5 1 -1 -1 1
4
-1 -1 0 -1
4
-1 1 1 -1
3
3 3 -1
5
0 0 0 0 0
7
3 0 1 4 -1 2 3
stdout
YES
NO
NO
NO
YES
YES
NO
NO