Naxocist

cardFlipping

Apr 29th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e6 + 3;
  5. int state[N];
  6.  
  7. int main() {
  8.  
  9.     int n; scanf("%d", &n);
  10.     for(int i=1; i<=n; ++i) {
  11.         scanf("%d", &state[i]);
  12.     }
  13.  
  14.     for(int i=1; i<=n; ++i) {
  15.         if(state[i] == -1 || i < 1) continue ;
  16.  
  17.         if(state[i] == 1) {
  18.             printf("%d ", i);
  19.             state[i] = -1;
  20.             if(state[i-1] >= 0) state[i-1] ^= 1;
  21.             if(state[i+1] >= 0) state[i+1] ^= 1;
  22.         }
  23.         if(state[i-1] == 1) i-=2;
  24.     }
  25.  
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment