Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int q, len;
- int main(){
- int s, d, x, ask, st, tmp;
- bool cs, cd;
- char c;
- scanf("%d %d", &q, &len);
- for(int k = 1; k <= q; ++k){
- vector<int> ans(len + 1, -1);
- vector<int> status(len / 2 + 1, 0); /// Don't Know = 0 Same = 1 Different = 2
- s = 0;
- d = 0;
- ask = 1;
- st = 1; /// st 1 => cout ask st 2 => cout len - ask + 1
- int i = 1;
- while(i <= 150 && ask <= len / 2){
- if(i % 10 == 1){
- cs = false;
- cd = false;
- if(s != 0){
- cout << s << "\n";
- fflush(stdout);
- scanf(" %c", &c);
- if(c == 'N'){
- exit(0);
- }
- x = c - '0';
- if(x != ans[s]){
- cs = true;
- }
- ++i;
- }
- if(d != 0){
- cout << d << "\n";
- fflush(stdout);
- scanf(" %c", &c);
- if(c == 'N'){
- exit(0);
- }
- x = c - '0';
- if(x != ans[d]){
- cd = true;
- }
- ++i;
- }
- if(cs || cd){
- for(int j = 1; j <= len / 2; ++j){
- if(status[j] == 1 && cs){
- ans[j] = (1 - ans[j]);
- ans[len - j + 1] = (1 - ans[len - j + 1]);
- } else if(status[j] == 2 && cd){
- ans[j] = (1 - ans[j]);
- ans[len - j + 1] = (1 - ans[len - j + 1]);
- }
- }
- if(st == 2){
- st = 1;
- }
- }
- }
- if(st == 1){
- tmp = ask;
- } else if(st == 2){
- tmp = len - ask + 1;
- }
- cout << tmp << "\n";
- fflush(stdout);
- scanf(" %c", &c);
- if(c == 'N'){
- exit(0);
- }
- x = c - '0';
- ans[tmp] = x;
- /// Check if Same/Different with its pair
- if(st == 2){
- if(ans[ask] != x){
- d = ask;
- status[ask] = 2;
- } else {
- s = ask;
- status[ask] = 1;
- }
- ++ask;
- }
- st = 3 - st;
- ++i;
- }
- for(int i = 1; i <= len; ++i){
- cout << ans[i];
- }
- cout << "\n";
- fflush(stdout);
- scanf(" %c", &c);
- if(c == 'N'){
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement