Advertisement
Ankit_132

D

Mar 11th, 2024
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define ss     second
  9. #define pb     push_back
  10.  
  11. int main()
  12. {
  13.     _test
  14.     {
  15.         int n, m, x;
  16.         cin>>n>>m>>x;
  17.  
  18.         vector<int> a(n+1), b(n+1);
  19.  
  20.         a[x-1] = 1;
  21.  
  22.         for(int i=0; i<m; i++)
  23.         {
  24.             int d;
  25.             char c;
  26.             cin>>d>>c;
  27.  
  28.             fill(b.begin(), b.end(), 0);
  29.  
  30.             for(int j=0; j<n; j++)
  31.             {
  32.                 if(!a[j])       continue;
  33.  
  34.                 if(c=='0' || c=='?')    b[(j+d)%n] = 1;
  35.                 if(c=='1' || c=='?')    b[(n+(j-d))%n] = 1;
  36.             }
  37.  
  38.             a = b;
  39.         }
  40.  
  41.         cout<<count(a.begin(), a.end(), 1)<<"\n";
  42.         for(int i=0; i<n; i++)
  43.         {
  44.             if(a[i])
  45.                 cout<<i+1<<" ";
  46.         }
  47.         cout<<"\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement