結果

問題 No.850 企業コンテスト2位
ユーザー uwiuwi
提出日時 2019-07-05 22:18:53
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,537 bytes
コンパイル時間 4,033 ms
コンパイル使用メモリ 81,428 KB
実行使用メモリ 75,784 KB
平均クエリ数 206.57
最終ジャッジ日時 2023-09-23 17:29:11
合計ジャッジ時間 12,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
72,676 KB
testcase_01 AC 174 ms
72,900 KB
testcase_02 AC 158 ms
72,916 KB
testcase_03 AC 180 ms
72,660 KB
testcase_04 AC 174 ms
72,152 KB
testcase_05 AC 176 ms
72,940 KB
testcase_06 AC 172 ms
72,464 KB
testcase_07 AC 209 ms
73,024 KB
testcase_08 AC 218 ms
72,956 KB
testcase_09 AC 222 ms
71,188 KB
testcase_10 AC 251 ms
72,784 KB
testcase_11 AC 253 ms
73,104 KB
testcase_12 AC 249 ms
73,472 KB
testcase_13 AC 253 ms
73,300 KB
testcase_14 AC 250 ms
73,700 KB
testcase_15 AC 241 ms
73,088 KB
testcase_16 AC 242 ms
72,884 KB
testcase_17 AC 251 ms
72,576 KB
testcase_18 AC 253 ms
72,812 KB
testcase_19 AC 249 ms
72,596 KB
testcase_20 AC 249 ms
73,212 KB
testcase_21 AC 251 ms
73,424 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 175 ms
71,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class E2 {
	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();
		Random gen = new Random();
		int[] ord = shuffle(n, gen);
		for(int i = 0;i < n;i++)ord[i]++;
		int o1 = 0, o2 = 0;
		if(stronger(ord[0], ord[1]) == ord[0]) {
			o1 = ord[0];
			o2 = ord[1];
		}else {
			o1 = ord[1];
			o2 = ord[0];
		}
		for(int i = 2;i < n;i++) {
			if(stronger(ord[i], o2) == ord[i]) {
				if(stronger(ord[i], o1) == ord[i]) {
					o2 = o1;
					o1 = ord[i];
				}else {
					o2 = ord[i];
				}
			}
		}
		out.println("! " + o2);
		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