Submission #254778

#TimeUsernameProblemLanguageResultExecution timeMemory
254778model_codeColors (BOI20_colors)Java
100 / 100
118 ms10612 KiB
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; public class Colors { static StreamTokenizer in; static PrintWriter out; static int nextInt() throws IOException { in.nextToken(); return Integer.parseInt(in.sval); } static long nextLong() throws IOException { in.nextToken(); return Long.parseLong(in.sval); } static long n; static long last; static long plast; static int lastAnswer; static int ask(long x) throws IOException { out.print("? "); out.println(x); out.flush(); int v = nextInt(); return v; } static void ask4(long x) throws IOException { plast = last; last = x; lastAnswer = ask(x); } static void giveAnswer(long x) { out.print("= "); out.println(x); out.flush(); } static long mas[] = new long[70]; public static void main(String[] args) throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); in.resetSyntax(); in.whitespaceChars(0, 32); in.wordChars('0', '9'); in.wordChars('-', '-'); n = nextLong(); int i = 0; mas[0] = n; if (mas[0] > 2) { while (mas[i] > 4) { i++; mas[i] = mas[i - 1] / 2 + mas[i - 1] % 2; } boolean aug = true; long f = 2; for (int j = i - 1; j >= 0; j--) { aug = !aug; if (!aug) { f = mas[j] + f - mas[j + 1]; } } long add1 = 0; long add2 = 0; ask4(f); for (int j = 0; j < i; j++) { long g = mas[j] - mas[j + 1] + add2; if (aug) { ask4(last + g); } else { ask4(last - g); } // if (lastAnswer && aug) // { // add1 += g; // } if (lastAnswer == 0) { add2 += mas[j] - mas[j + 1]; } aug = !aug; } if (mas[i] == 3) { ask4(last + add2 + 1); if (lastAnswer == 0) { ask4(last - add2 - 2); if (lastAnswer > 0) { giveAnswer(add2 + 2); } else { giveAnswer(add2 + 3); } } else { giveAnswer(add2 + 1); } } else if (mas[i] == 4) { ask4(last + add2 + 2); if (lastAnswer > 0) { ask4(last - add2 - 1); if (lastAnswer > 0) { giveAnswer(add2 + 1); } else { giveAnswer(add2 + 2); } } else { ask4(last - add2 - 3); if (lastAnswer > 0) { giveAnswer(add2 + 3); } else { giveAnswer((add2 + 4)); } } } } else { ask4(1); ask4(2); if (lastAnswer > 0) { giveAnswer(1); } else { giveAnswer(2); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...