public class ESAbATAd {
    public static void main(String[] args) {
        Scanner ms = new Scanner(System.in);
        int t = ms.nextInt();
        int b = ms.nextInt();
        while (t-- > 0) {
            int q = 0;
            int[] ans = new int[b];
            int same = -1;
            int diff = -1;
            int i = 1;
            int[] isSame = new int[b];
            int found = 0;
            Arrays.fill(isSame, -1);
            while (found < b) {
                if (q > 9 && q%10 == 0) {
                   if (same != -1 && diff != -1) {
                       System.out.println(same+1);
                       int l = ms.nextInt();
                       System.out.println(diff+1);
                       int r = ms.nextInt();
                       if (ans[diff] == r && ans[same] != l) {
                           for (int j=0;j<b;j++) {
                               if (isSame[j] == 1) {
                                   ans[j] = 1 - ans[j];
                               }
                           }
                       }
                       else if (ans[diff] != r && ans[same] == l) {
                           for (int j=0;j<b;j++) {
                               if (isSame[j] == 0) {
                                   ans[j] = 1 - ans[j];
                               }
                           }
                       } else if (ans[diff] != r && ans[same] != l) {
                           for (int j=0;j<b;j++) {
                               if (isSame[j] != -1) {
                                   ans[j] = 1 - ans[j];
                               }
                           }
                       }
                   } else if (same != -1) {
                       System.out.println(same+1);
                       int l = ms.nextInt();
                       if (ans[same] != l) {
                           for (int j=0;j<b;j++) {
                               if (isSame[j] == 1) {
                                   ans[j] = 1 - ans[j];
                               }
                           }
                       }
                       System.out.println(same+1);
                       ms.nextInt();
                   } else if (diff != -1) {
                       System.out.println(diff+1);
                       int l = ms.nextInt();
                       if (ans[diff] != l) {
                           for (int j=0;j<b;j++) {
                               if (isSame[j] == 0) {
                                   ans[j] = 1 - ans[j];
                               }
                           }
                       }
                       System.out.println(same+1);
                       ms.nextInt();
                   }
                } else {
                    System.out.println(i);
                    int left = ms.nextInt();
                    System.out.println(b-i+1);
                    int right = ms.nextInt();
                    ans[i-1] = left;
                    ans[b-i] = right;
                    if (left == right) {
                        isSame[i-1] = 1;
                        isSame[b-i] = 1;
                        same = (i-1);
                    } else {
                        isSame[i-1] = 0;
                        isSame[b-i] = 0;
                        diff = (i-1);
                    }
                    i++;
                    found += 2;
                }
                q+=2;
            }

            
System.out.println(Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining()));
            String response = ms.next();
            if ("N".equalsIgnoreCase(response)) {
                return;
            }
        }
    }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/59de6734-9b3e-4e59-b309-d9b2d3f97904%40googlegroups.com.

Reply via email to