Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<bits/stdc++.h>
- #include<algorithm>
- #include<limits>
- #define INFL 1000000000000000007
- #define INF 1000000007
- #define MOD 998244353
- #define N 50005
- #define K 505
- #define sh 400004
- #define M 8
- #define ll long long
- using namespace std;
- int reads;
- char scan;
- int f;
- string rev(string a)
- {
- //just reverse the string
- for(int i=0;i<a.length()/2;i++)
- swap(a[i],a[a.length()-1-i]);
- return a;
- }
- string comp(string a)
- {
- //just complement the string
- for(int i=0;i<a.length();i++){
- if(a[i]=='0') a[i]='1';
- else a[i]='0';
- }
- return a;
- }
- string dic(string a,string b)
- {
- int d=0;
- //look for index for mismatch between strings
- while(d<a.length() && a[d]==b[d])
- d++;
- //if no mismatch found return any
- if(d==a.length())
- return a;
- //else read and return the right one
- reads--;
- //increase d by 1 as it is 1 indexed
- printf("%d\n",d+1);
- cout.flush();
- cin >> scan;
- //only checking for unexpected behavior
- if(scan=='\n') cin >> scan;
- if(scan=='N') f=0;
- //comparing scanned char to position in string
- if(scan==a[d])
- return a;
- return b;
- }
- int main()
- {
- int T,b;
- cin >> T >> b;
- int f=1;
- for(int q=1;q<=T;q++){
- string s;
- cin >> s;
- //only checking for N
- if(s=="N") return 0;
- // 15*10 reads
- for(int i=0;i<15;i++){
- //we need 10 reads every iteration
- reads=10;
- string poss[4];
- // generate four possibilities for string
- poss[0]=s;
- poss[1]=comp(s);
- poss[2]=rev(s);
- poss[3]=rev(poss[1]);
- //making decision about what is the string in 3 steps
- poss[1]=dic(poss[0],poss[1]);
- //f flag for ending if N scanned
- if(f==0)
- return 0;
- poss[2]=dic(poss[2],poss[1]);
- if(f==0)
- return 0;
- // reassign s at the last decision made
- s=dic(poss[2],poss[3]);
- if(f==0)
- return 0;
- //just make the reaming reads
- for(int j=0;j<reads;j++){
- printf("1\n");
- cout.flush();
- cin >> scan;
- //only checking for unexpected behavior
- if(scan=='\n')
- cin >> scan;
- if(scan=='N')
- return 0;
- }
- }
- //output s after 150 query
- cout << s << endl;
- cout.flush();
- // to scan Y here or N :(
- cin >> scan;
- //only checking for unexpected behavior
- if(scan=='\n')
- cin >> scan;
- if(scan=='N')
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement