結果

問題 No.850 企業コンテスト2位
ユーザー pekempeypekempey
提出日時 2019-07-05 23:08:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 167,428 KB
実行使用メモリ 24,384 KB
平均クエリ数 252.89
最終ジャッジ日時 2023-09-23 17:39:34
合計ジャッジ時間 4,902 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,832 KB
testcase_01 AC 24 ms
23,376 KB
testcase_02 AC 25 ms
23,892 KB
testcase_03 AC 25 ms
23,352 KB
testcase_04 AC 24 ms
23,352 KB
testcase_05 AC 25 ms
23,340 KB
testcase_06 AC 26 ms
23,496 KB
testcase_07 AC 28 ms
23,376 KB
testcase_08 AC 31 ms
23,316 KB
testcase_09 AC 31 ms
24,324 KB
testcase_10 AC 34 ms
23,892 KB
testcase_11 AC 35 ms
23,364 KB
testcase_12 AC 35 ms
23,316 KB
testcase_13 AC 34 ms
24,192 KB
testcase_14 AC 34 ms
23,508 KB
testcase_15 AC 34 ms
23,976 KB
testcase_16 AC 33 ms
23,340 KB
testcase_17 AC 35 ms
23,328 KB
testcase_18 AC 34 ms
24,240 KB
testcase_19 AC 35 ms
24,228 KB
testcase_20 AC 35 ms
23,484 KB
testcase_21 AC 34 ms
24,132 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 24 ms
23,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int cnt;
#ifdef DEBUG
int a[300];
bool lt(int x, int y) {
  cnt++;
  return a[x] > a[y];
}
#else
bool lt(int x, int y) {
  cnt++;
  cout << "? " << x+1 << ' ' << y+1 << endl;
  int res;
  cin >> res;
  return res == y+1 ? 1 : 0;
}
#endif

int main() {
  // cin.tie(nullptr);
  // ios::sync_with_stdio(false);
  mt19937 mt(123);
#ifdef DEBUG
  rep(i, 300) a[i] = i;
  int n = 300;
#else
  int n;
  cin >> n;
#endif
  vector<int> ord(n);
  rep(i, n) ord[i] = i;

  for (int i = 0; i < n; i++) {
    int r = uniform_int_distribution<int>(0, i)(mt);
    swap(ord[i], ord[r]);
  }
  int first, second;
  if (lt(ord[0], ord[1])) {
    first = ord[1];
    second = ord[0];
  } else {
    first = ord[0];
    second = ord[1];
  }
  for (int i = 2; i < n; i++) {
    if (lt(ord[i], second)) {
    } else if (lt(ord[i], first)) {
      second = ord[i];
    } else {
      second = first;
      first = ord[i];
    }
  }
  cout << "! " << second+1 << endl;
  cerr << cnt << endl;
}
0