Submission #1058359
Source Code Expand
import java.io.*; import java.util.*; public class Main { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int ret = 0; for (int i = 0; i < n; ) { int j = 1; while (i + j * 2 < n) { j *= 2; } pr.printf("? %d %d\n", i, i + j); pr.flush(); ret += sc.nextInt(); i += j; } pr.printf("! %d\n", ret); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } private boolean isPrintable(int ch) { return ch >= '!' && ch <= '~'; } private boolean isCRLF(int ch) { return ch == '\n' || ch == '\r' || ch == -1; } private int nextPrintable() { try { int ch; while (!isPrintable(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } return ch; } catch (IOException e) { throw new NoSuchElementException(); } } String next() { try { int ch = nextPrintable(); StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (isPrintable(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } int nextInt() { try { // parseInt from Integer.parseInt() boolean negative = false; int res = 0; int limit = -Integer.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Integer.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } int multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } long nextLong() { try { // parseLong from Long.parseLong() boolean negative = false; long res = 0; long limit = -Long.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Long.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } long multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } float nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { int ch; while (isCRLF(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (!isCRLF(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } void close() { try { br.close(); } catch (IOException e) { // throw new NoSuchElementException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Array Sum |
User | garnacha |
Language | Java8 (OpenJDK 1.8.0) |
Score | 52 |
Code Size | 4315 Byte |
Status | AC |
Exec Time | 115 ms |
Memory | 9632 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 52 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 107 ms | 8996 KB |
01-02.txt | AC | 107 ms | 9000 KB |
01-03.txt | AC | 108 ms | 8996 KB |
01-04.txt | AC | 107 ms | 9000 KB |
01-05.txt | AC | 115 ms | 9372 KB |
01-06.txt | AC | 109 ms | 9376 KB |
01-07.txt | AC | 110 ms | 9372 KB |
01-08.txt | AC | 108 ms | 9372 KB |
01-09.txt | AC | 110 ms | 9376 KB |
01-10.txt | AC | 111 ms | 9500 KB |
01-11.txt | AC | 111 ms | 9364 KB |
01-12.txt | AC | 110 ms | 9496 KB |
01-13.txt | AC | 107 ms | 9500 KB |
01-14.txt | AC | 109 ms | 9500 KB |
01-15.txt | AC | 112 ms | 9500 KB |
01-16.txt | AC | 108 ms | 9504 KB |
01-17.txt | AC | 109 ms | 9496 KB |
01-18.txt | AC | 110 ms | 9632 KB |
01-19.txt | AC | 109 ms | 9244 KB |
01-20.txt | AC | 110 ms | 9368 KB |
01-21.txt | AC | 108 ms | 9500 KB |
01-22.txt | AC | 109 ms | 9368 KB |
01-23.txt | AC | 111 ms | 9376 KB |
01-24.txt | AC | 109 ms | 9372 KB |