結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-05 22:18:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,537 bytes |
| コンパイル時間 | 3,567 ms |
| コンパイル使用メモリ | 82,076 KB |
| 実行使用メモリ | 72,936 KB |
| 平均クエリ数 | 206.39 |
| 最終ジャッジ日時 | 2024-07-16 17:22:05 |
| 合計ジャッジ時間 | 12,108 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 RE * 5 |
ソースコード
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)); }
}