Submission #1171274


Source Code Expand

// package atcoder.arc.arc070;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        int a = in.nextInt();
        int b = in.nextInt();
        if (a <= b) {
            out.println("Impossible");
            out.flush();
            return;
        }

        int n = a + b;
        if (n == 1) {
            out.println("! 1");
            out.flush();
            return;
        }

        map = new int[n][n];
        int[] co = new int[n+1];
        for (int i = 0; i < n ; i++) {
            if (question(i, (i+1)%n)) {
                co[i+1] = co[i] + 1;
            } else {
                co[i+1] = 0;
            }
        }

        int max = 0;
        int rightPerson = -1;
        for (int i = 1 ; i <= n ; i++) {
            if (max < co[i]) {
                max = co[i];
                rightPerson = i % n;
            }
        }

        StringBuilder ans = new StringBuilder();
        ans.append("! ");
        for (int i = 0; i < n ; i++) {
            ans.append(question(rightPerson, i) ? '1' : '0');
        }
        out.println(ans.toString());
        out.flush();
    }

    static InputReader in;
    static PrintWriter out;
    static int[][] map;

    static boolean question(int a, int b) {
        if (a == b) {
            return true;
        }
        if (map[a][b] == 0) {
            out.println(String.format("? %d %d", a, b));
            out.flush();
            char ret = in.nextToken().toCharArray()[0];
            map[a][b] = ret == 'Y' ? 1 : -1;
            return ret == 'Y';
        } else {
            return map[a][b] == 1;
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int[] nextInts(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }

        private int[][] nextIntTable(int n, int m) {
            int[][] ret = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextInt();
                }
            }
            return ret;
        }

        private long[] nextLongs(int n) {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }

        private long[][] nextLongTable(int n, int m) {
            long[][] ret = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextLong();
                }
            }
            return ret;
        }

        private double[] nextDoubles(int n) {
            double[] ret = new double[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextDouble();
            }
            return ret;
        }

        private int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}

Submission Info

Submission Time
Task F - HonestOrUnkind
User hamadu
Language Java8 (OpenJDK 1.8.0)
Score 1300
Code Size 6245 Byte
Status AC
Exec Time 594 ms
Memory 136344 KB

Judge Result

Set Name All
Score / Max Score 1300 / 1300
Status
AC × 126
Set Name Test Cases
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, 091.txt, 092.txt, 093.txt, 094.txt, 095.txt, 096.txt, 097.txt, 098.txt, 099.txt, 100.txt, 101.txt, 102.txt, 103.txt, 104.txt, 105.txt, 106.txt, 107.txt, 108.txt, 109.txt, 110.txt, 111.txt, 112.txt, 113.txt, 114.txt, 115.txt, 116.txt, 117.txt, 118.txt, 119.txt, 120.txt, 121.txt, 122.txt, 123.txt, 124.txt, 125.txt
Case Name Status Exec Time Memory
000.txt AC 85 ms 20004 KB
001.txt AC 75 ms 18852 KB
002.txt AC 73 ms 18852 KB
003.txt AC 74 ms 19876 KB
004.txt AC 74 ms 23588 KB
005.txt AC 74 ms 20004 KB
006.txt AC 77 ms 21668 KB
007.txt AC 75 ms 23720 KB
008.txt AC 76 ms 19492 KB
009.txt AC 74 ms 20772 KB
010.txt AC 150 ms 22440 KB
011.txt AC 538 ms 135196 KB
012.txt AC 322 ms 52900 KB
013.txt AC 83 ms 19876 KB
014.txt AC 83 ms 18340 KB
015.txt AC 75 ms 20772 KB
016.txt AC 75 ms 20008 KB
017.txt AC 74 ms 21156 KB
018.txt AC 73 ms 19748 KB
019.txt AC 76 ms 17572 KB
020.txt AC 74 ms 21668 KB
021.txt AC 76 ms 18852 KB
022.txt AC 77 ms 19364 KB
023.txt AC 132 ms 22436 KB
024.txt AC 546 ms 133192 KB
025.txt AC 325 ms 55664 KB
026.txt AC 78 ms 18724 KB
027.txt AC 83 ms 21412 KB
028.txt AC 75 ms 16288 KB
029.txt AC 76 ms 21536 KB
030.txt AC 76 ms 21032 KB
031.txt AC 75 ms 19492 KB
032.txt AC 74 ms 21668 KB
033.txt AC 75 ms 20896 KB
034.txt AC 75 ms 21668 KB
035.txt AC 75 ms 21672 KB
036.txt AC 139 ms 21484 KB
037.txt AC 516 ms 136344 KB
038.txt AC 341 ms 51980 KB
039.txt AC 84 ms 21152 KB
040.txt AC 85 ms 18720 KB
041.txt AC 77 ms 19364 KB
042.txt AC 82 ms 21156 KB
043.txt AC 73 ms 19748 KB
044.txt AC 74 ms 17448 KB
045.txt AC 76 ms 23588 KB
046.txt AC 74 ms 20004 KB
047.txt AC 75 ms 18212 KB
048.txt AC 76 ms 18468 KB
049.txt AC 135 ms 21872 KB
050.txt AC 491 ms 134876 KB
051.txt AC 329 ms 51664 KB
052.txt AC 74 ms 21668 KB
053.txt AC 73 ms 19876 KB
054.txt AC 76 ms 21156 KB
055.txt AC 74 ms 18464 KB
056.txt AC 76 ms 21540 KB
057.txt AC 74 ms 18596 KB
058.txt AC 74 ms 21796 KB
059.txt AC 74 ms 19748 KB
060.txt AC 74 ms 19748 KB
061.txt AC 77 ms 19620 KB
062.txt AC 126 ms 22560 KB
063.txt AC 594 ms 133056 KB
064.txt AC 330 ms 52720 KB
065.txt AC 85 ms 19364 KB
066.txt AC 86 ms 20388 KB
067.txt AC 73 ms 19620 KB
068.txt AC 75 ms 19108 KB
069.txt AC 75 ms 21792 KB
070.txt AC 76 ms 20520 KB
071.txt AC 76 ms 19492 KB
072.txt AC 76 ms 19364 KB
073.txt AC 78 ms 21412 KB
074.txt AC 77 ms 20392 KB
075.txt AC 140 ms 21104 KB
076.txt AC 564 ms 135120 KB
077.txt AC 344 ms 55388 KB
078.txt AC 83 ms 25252 KB
079.txt AC 73 ms 20260 KB
080.txt AC 73 ms 21664 KB
081.txt AC 73 ms 20260 KB
082.txt AC 74 ms 18724 KB
083.txt AC 73 ms 21800 KB
084.txt AC 75 ms 20388 KB
085.txt AC 75 ms 19876 KB
086.txt AC 75 ms 23072 KB
087.txt AC 75 ms 18468 KB
088.txt AC 122 ms 20260 KB
089.txt AC 528 ms 131504 KB
090.txt AC 329 ms 55148 KB
091.txt AC 76 ms 19236 KB
092.txt AC 73 ms 18976 KB
093.txt AC 75 ms 19492 KB
094.txt AC 73 ms 21668 KB
095.txt AC 77 ms 20644 KB
096.txt AC 75 ms 20644 KB
097.txt AC 75 ms 16420 KB
098.txt AC 81 ms 21664 KB
099.txt AC 75 ms 21540 KB
100.txt AC 82 ms 19496 KB
101.txt AC 131 ms 23972 KB
102.txt AC 501 ms 136060 KB
103.txt AC 342 ms 53432 KB
104.txt AC 85 ms 21792 KB
105.txt AC 73 ms 21672 KB
106.txt AC 75 ms 16292 KB
107.txt AC 74 ms 20004 KB
108.txt AC 73 ms 21540 KB
109.txt AC 75 ms 21668 KB
110.txt AC 73 ms 18724 KB
111.txt AC 74 ms 21668 KB
112.txt AC 76 ms 20132 KB
113.txt AC 76 ms 21544 KB
114.txt AC 136 ms 21412 KB
115.txt AC 520 ms 134580 KB
116.txt AC 333 ms 50760 KB
117.txt AC 68 ms 19492 KB
118.txt AC 71 ms 19876 KB
119.txt AC 71 ms 19236 KB
120.txt AC 69 ms 19364 KB
121.txt AC 69 ms 21156 KB
122.txt AC 70 ms 19488 KB
123.txt AC 70 ms 20388 KB
124.txt AC 68 ms 21540 KB
125.txt AC 69 ms 19620 KB