Submission #347320


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	
	public void run() {
		int n = in.nextInt();
		System.out.println("? 1 2");
		int a = 1, b = 2;
		int max = in.nextInt();
		for (int i = 3; i <= n; i++) {
			System.out.println("? " + a + " " + i);
			int d1 = in.nextInt();
			System.out.println("? " + b + " " + i);
			int d2 = in.nextInt();
			if (d1 >= d2 && d1 > max) {
				b = i;
				max = d1;
			} else if (d2 >= d1 && d2 > max) {
				a = i;
				max = d2;
			}
		}
		System.out.println("! " + max);
		
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

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

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			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++];
		}

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

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

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Submission Info

Submission Time
Task D - 高橋くんと木の直径
User hiro116s
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 3943 Byte
Status AC
Exec Time 316 ms
Memory 21040 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 20 / 20 80 / 80
Status
AC × 1
AC × 22
AC × 42
Set Name Test Cases
Sample subtask0_0.txt
Subtask1 subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_2.txt, subtask1_20.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt, subtask0_0.txt
All subtask0_0.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_2.txt, subtask1_20.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt, subtask2_0.txt, subtask2_1.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_2.txt, subtask2_3.txt, subtask2_4.txt, subtask2_5.txt, subtask2_6.txt, subtask2_7.txt, subtask2_8.txt, subtask2_9.txt
Case Name Status Exec Time Memory
subtask0_0.txt AC 292 ms 20884 KB
subtask1_0.txt AC 298 ms 20960 KB
subtask1_1.txt AC 310 ms 20896 KB
subtask1_10.txt AC 312 ms 20864 KB
subtask1_11.txt AC 311 ms 20972 KB
subtask1_12.txt AC 310 ms 20912 KB
subtask1_13.txt AC 307 ms 21016 KB
subtask1_14.txt AC 311 ms 21020 KB
subtask1_15.txt AC 313 ms 21040 KB
subtask1_16.txt AC 310 ms 20860 KB
subtask1_17.txt AC 310 ms 20972 KB
subtask1_18.txt AC 310 ms 20956 KB
subtask1_19.txt AC 309 ms 20960 KB
subtask1_2.txt AC 312 ms 20956 KB
subtask1_20.txt AC 297 ms 20860 KB
subtask1_3.txt AC 312 ms 20888 KB
subtask1_4.txt AC 307 ms 20976 KB
subtask1_5.txt AC 315 ms 20872 KB
subtask1_6.txt AC 313 ms 20968 KB
subtask1_7.txt AC 311 ms 20948 KB
subtask1_8.txt AC 313 ms 20944 KB
subtask1_9.txt AC 306 ms 20976 KB
subtask2_0.txt AC 309 ms 20872 KB
subtask2_1.txt AC 308 ms 20924 KB
subtask2_10.txt AC 310 ms 20948 KB
subtask2_11.txt AC 312 ms 20964 KB
subtask2_12.txt AC 314 ms 20920 KB
subtask2_13.txt AC 316 ms 20896 KB
subtask2_14.txt AC 311 ms 20944 KB
subtask2_15.txt AC 311 ms 21000 KB
subtask2_16.txt AC 312 ms 21004 KB
subtask2_17.txt AC 308 ms 20868 KB
subtask2_18.txt AC 310 ms 20972 KB
subtask2_19.txt AC 312 ms 20888 KB
subtask2_2.txt AC 312 ms 20860 KB
subtask2_3.txt AC 308 ms 20980 KB
subtask2_4.txt AC 302 ms 20960 KB
subtask2_5.txt AC 309 ms 20916 KB
subtask2_6.txt AC 303 ms 20960 KB
subtask2_7.txt AC 308 ms 20928 KB
subtask2_8.txt AC 314 ms 20900 KB
subtask2_9.txt AC 315 ms 20908 KB