結果

問題 No.850 企業コンテスト2位
ユーザー uwiuwi
提出日時 2019-07-05 22:28:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 2,106 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 78,716 KB
実行使用メモリ 73,436 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:31:25
合計ジャッジ時間 12,241 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
72,228 KB
testcase_01 AC 179 ms
72,228 KB
testcase_02 AC 165 ms
72,484 KB
testcase_03 AC 167 ms
72,792 KB
testcase_04 AC 178 ms
72,628 KB
testcase_05 AC 171 ms
72,900 KB
testcase_06 AC 167 ms
72,688 KB
testcase_07 AC 211 ms
72,744 KB
testcase_08 AC 220 ms
72,804 KB
testcase_09 AC 218 ms
73,352 KB
testcase_10 AC 249 ms
73,140 KB
testcase_11 AC 244 ms
72,776 KB
testcase_12 AC 248 ms
72,780 KB
testcase_13 AC 249 ms
73,436 KB
testcase_14 AC 246 ms
73,212 KB
testcase_15 AC 245 ms
73,032 KB
testcase_16 AC 248 ms
71,520 KB
testcase_17 AC 249 ms
72,744 KB
testcase_18 AC 244 ms
72,960 KB
testcase_19 AC 246 ms
73,420 KB
testcase_20 AC 243 ms
73,344 KB
testcase_21 AC 251 ms
73,356 KB
testcase_22 AC 249 ms
72,848 KB
testcase_23 AC 243 ms
73,004 KB
testcase_24 AC 246 ms
73,220 KB
testcase_25 AC 249 ms
71,432 KB
testcase_26 AC 247 ms
72,848 KB
testcase_27 AC 178 ms
72,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package contest190705;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class E3 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static int stronger(int x, int y)
	{
		out.println("? " + x + " " + y);
		out.flush();
		return ni();
	}
	
	static void solve()
	{
		int n = ni();
		int[] can = new int[n];
		for(int i = 0;i < n;i++)can[i] = i+1;
		
		int[][] hist = new int[334][];
		int q = 0;
		
		while(can.length > 1) {
			int[] ncan = new int[can.length];
			int p = 0;
			for(int i = 0;i < can.length;i+=2) {
				if(i+1 < can.length) {
					int res = stronger(can[i], can[i+1]);
					hist[q++] = new int[] {can[i], can[i+1], res};
					ncan[p++] = res;
				}else {
					ncan[p++] = can[i];
				}
			}
			can = Arrays.copyOf(ncan, p);
		}
		
		int[] xcan = new int[n];
		int u = 0;
		for(int i = 0;i < q;i++) {
			if(hist[i][0] == can[0] || hist[i][1] == can[0]) {
				xcan[u++] = hist[i][0]^hist[i][1]^hist[i][2];
			}
		}
		xcan = Arrays.copyOf(xcan, u);
		
		while(xcan.length > 1) {
			int[] ncan = new int[xcan.length];
			int p = 0;
			for(int i = 0;i < xcan.length;i+=2) {
				if(i+1 < xcan.length) {
					int res = stronger(xcan[i], xcan[i+1]);
					ncan[p++] = res;
				}else {
					ncan[p++] = xcan[i];
				}
			}
			xcan = Arrays.copyOf(ncan, p);
		}
		
		out.println("! " + xcan[0]);
		out.flush();
	}
	
	public static int[] shuffle(int n, Random gen){ int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = i; for(int i = 0;i < n;i++){ int ind = gen.nextInt(n-i)+i; int d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; }

	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0