結果

問題 No.850 企業コンテスト2位
ユーザー lowrlowr
提出日時 2019-08-16 20:35:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 206,176 KB
実行使用メモリ 24,252 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 18:02:34
合計ジャッジ時間 5,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,228 KB
testcase_01 AC 27 ms
23,592 KB
testcase_02 AC 27 ms
23,460 KB
testcase_03 AC 26 ms
23,568 KB
testcase_04 AC 26 ms
23,364 KB
testcase_05 AC 27 ms
23,304 KB
testcase_06 AC 27 ms
23,964 KB
testcase_07 AC 30 ms
23,472 KB
testcase_08 AC 32 ms
23,604 KB
testcase_09 AC 32 ms
23,292 KB
testcase_10 AC 37 ms
24,228 KB
testcase_11 AC 37 ms
23,556 KB
testcase_12 AC 38 ms
24,252 KB
testcase_13 AC 36 ms
24,180 KB
testcase_14 AC 36 ms
23,616 KB
testcase_15 AC 36 ms
23,772 KB
testcase_16 AC 36 ms
23,484 KB
testcase_17 AC 36 ms
23,784 KB
testcase_18 AC 35 ms
24,156 KB
testcase_19 AC 36 ms
23,340 KB
testcase_20 AC 36 ms
23,352 KB
testcase_21 AC 38 ms
23,484 KB
testcase_22 AC 37 ms
23,592 KB
testcase_23 AC 37 ms
23,484 KB
testcase_24 AC 38 ms
24,228 KB
testcase_25 AC 37 ms
23,304 KB
testcase_26 AC 38 ms
23,760 KB
testcase_27 AC 27 ms
23,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;

int ask(int a, int b) {
  printf("? %d %d\n", a, b);
  fflush(stdout);
  int ret;
  scanf("%d", &ret);
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> cs;
  for (int i = 1; i <= n; i++) cs.push_back(i);
  std::vector<std::vector<int>> wl(n + 1, std::vector<int>(n + 1));
  while (cs.size() > 1) {
    std::vector<int> next;
    for (int i = 1; 2 * i - 1 < cs.size(); i++) {
      int w = ask(cs[2 * i - 2], cs[2 * i - 1]);
      int l = cs[2 * i - 2] ^ cs[2 * i - 1] ^ w;
      next.push_back(w);
      wl[w][l] = 1;
      wl[l][w] = -1;
    }
    if (cs.size() & 1) next.push_back(cs.back());
    std::swap(next, cs);
  }

  int f = cs.front();
  std::vector<int> cand;
  for (int i = 1; i <= n; i++) if (wl[f][i] > 0) cand.push_back(i);

  while (cand.size() > 1) {
    std::vector<int> next;
    for (int i = 1; 2 * i - 1 < cand.size(); i++) {
      next.push_back(ask(cand[2 * i - 2], cand[2 * i - 1]));
    }
    if (cand.size() & 1) next.push_back(cand.back());
    std::swap(next, cand);
  }

  printf("! %d\n", cand.front());
  fflush(stdout);

  return 0;
}

0