結果

問題 No.850 企業コンテスト2位
ユーザー uwiuwi
提出日時 2019-07-05 22:17:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 4,615 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 74,040 KB
平均クエリ数 203.68
最終ジャッジ日時 2023-09-23 17:28:51
合計ジャッジ時間 12,595 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
72,228 KB
testcase_01 AC 156 ms
72,184 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 159 ms
72,468 KB
testcase_07 AC 205 ms
72,780 KB
testcase_08 AC 209 ms
73,072 KB
testcase_09 AC 218 ms
72,576 KB
testcase_10 AC 239 ms
72,748 KB
testcase_11 AC 240 ms
72,472 KB
testcase_12 AC 238 ms
73,300 KB
testcase_13 AC 238 ms
73,116 KB
testcase_14 AC 238 ms
73,036 KB
testcase_15 AC 243 ms
72,716 KB
testcase_16 AC 241 ms
70,812 KB
testcase_17 AC 243 ms
73,180 KB
testcase_18 AC 227 ms
71,292 KB
testcase_19 AC 238 ms
72,576 KB
testcase_20 AC 239 ms
72,584 KB
testcase_21 AC 238 ms
73,176 KB
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 AC 172 ms
72,524 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(1414);
		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]) == 1) {
			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