fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void solve() {
  7. int n;
  8. cin >> n;
  9.  
  10. vector<int> a(n + 1);
  11. for (int i = 1; i <= n; i++) {
  12. cin >> a[i];
  13. }
  14.  
  15. if (a[1] == 1) {
  16. cout << n + 1;
  17. for (int i = 1; i <= n; i++) {
  18. cout << " " << i;
  19. }
  20. cout << "\n";
  21. return;
  22. }
  23.  
  24. if (a[n] == 0) {
  25. for (int i = 1; i <= n; i++) {
  26. cout << i << " ";
  27. }
  28. cout << n + 1 << "\n";
  29. return;
  30. }
  31.  
  32. for (int i = 1; i < n; i++) {
  33. if (a[i] == 0 && a[i + 1] == 1) {
  34. for (int j = 1; j <= i; j++) {
  35. cout << j << " ";
  36. }
  37. cout << n + 1 << " ";
  38. for (int j = i + 1; j <= n; j++) {
  39. cout << j << (j == n ? "" : " ");
  40. }
  41. cout << "\n";
  42. return;
  43. }
  44. }
  45.  
  46. cout << -1 << "\n";
  47. }
  48.  
  49. int main() {
  50. ios_base::sync_with_stdio(false);
  51. cin.tie(NULL);
  52.  
  53. int t;
  54. cin >> t;
  55. while (t--) {
  56. solve();
  57. }
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 5324KB
stdin
2
3
0 1 0
3
1 1 0
stdout
1 2 3 4
4 1 2 3