結果

問題 No.850 企業コンテスト2位
ユーザー uwiuwi
提出日時 2019-07-05 22:27:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,099 bytes
コンパイル時間 3,525 ms
コンパイル使用メモリ 79,256 KB
実行使用メモリ 74,512 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:31:11
合計ジャッジ時間 15,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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