結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-05 22:10:45 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 1,179 bytes |
| コンパイル時間 | 810 ms |
| コンパイル使用メモリ | 114,208 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-06-22 01:51:44 |
| 合計ジャッジ時間 | 3,148 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
int ask(int a, int b) {
writeln("? ", a + 1, " ", b + 1);
stdout.flush;
return readln.chomp.to!int - 1;
}
void main() {
auto N = readln.chomp.to!int;
auto losers = new int[][](N);
int[] q1;
int[] q2;
foreach (i; 0..N) q1 ~= i;
while (q1.length > 1) {
q2 = [];
for (int i = 0; i + 1 < q1.length; i += 2) {
q2 ~= ask(q1[i], q1[i+1]);
if (q2.back == q1[i]) {
losers[q1[i]] ~= q1[i+1];
} else {
losers[q1[i+1]] ~= q1[i];
}
}
if (q1.length % 2) {
q2 ~= q1.back;
}
swap(q1, q2);
}
q1 = losers[q1.front].dup;
q2 = [];
while (q1.length > 1) {
q2 = [];
for (int i = 0; i + 1 < q1.length; i += 2) {
q2 ~= ask(q1[i], q1[i+1]);
}
if (q1.length % 2) {
q2 ~= q1.back;
}
swap(q1, q2);
}
writeln("! ", q1.front + 1);
}