結果

問題 No.850 企業コンテスト2位
ユーザー pekempeypekempey
提出日時 2019-07-05 22:48:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,068 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 169,020 KB
実行使用メモリ 24,348 KB
平均クエリ数 201.82
最終ジャッジ日時 2023-09-23 17:35:27
合計ジャッジ時間 8,161 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 25 ms
23,700 KB
testcase_05 AC 24 ms
23,820 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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 == x+1 ? 1 : 0;
}
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
#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;
  mt19937 mt(time(NULL));
  shuffle(ord.begin(), ord.end(), mt);
  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