結果

問題 No.850 企業コンテスト2位
ユーザー uwi
提出日時 2019-07-05 22:17:04
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 3,502 ms
コンパイル使用メモリ 84,200 KB
実行使用メモリ 72,608 KB
平均クエリ数 203.68
最終ジャッジ日時 2024-07-16 17:21:49
合計ジャッジ時間 12,850 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18 WA * 6 RE * 3
権限があれば一括ダウンロードができます

ソースコード

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