結果

問題 No.850 企業コンテスト2位
ユーザー cotton_fn_cotton_fn_
提出日時 2019-07-06 03:32:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,488 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 120,520 KB
実行使用メモリ 24,324 KB
平均クエリ数 200.07
最終ジャッジ日時 2023-09-23 17:44:49
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,352 KB
testcase_01 AC 27 ms
24,156 KB
testcase_02 AC 26 ms
23,520 KB
testcase_03 AC 26 ms
23,868 KB
testcase_04 AC 26 ms
23,712 KB
testcase_05 AC 26 ms
23,340 KB
testcase_06 AC 26 ms
24,324 KB
testcase_07 AC 30 ms
23,568 KB
testcase_08 AC 32 ms
24,168 KB
testcase_09 AC 32 ms
23,592 KB
testcase_10 AC 37 ms
23,412 KB
testcase_11 AC 37 ms
23,916 KB
testcase_12 AC 37 ms
24,132 KB
testcase_13 AC 37 ms
23,412 KB
testcase_14 AC 37 ms
23,328 KB
testcase_15 AC 35 ms
23,376 KB
testcase_16 AC 35 ms
23,328 KB
testcase_17 AC 36 ms
24,264 KB
testcase_18 AC 36 ms
23,352 KB
testcase_19 AC 35 ms
23,892 KB
testcase_20 AC 36 ms
24,120 KB
testcase_21 AC 37 ms
23,976 KB
testcase_22 AC 36 ms
24,252 KB
testcase_23 AC 36 ms
23,520 KB
testcase_24 AC 36 ms
24,168 KB
testcase_25 AC 36 ms
24,168 KB
testcase_26 AC 38 ms
23,328 KB
testcase_27 AC 26 ms
23,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
pair<i64, vector<i64>> f(const vector<i64>& a) {
  vector<vector<i64>> w(n + 1);
  queue<i64> q;
  for (i64 x : a) q.push(x);
  while (q.size() >= 2) {
    i64 x = q.front(); q.pop();
    i64 y = q.front(); q.pop();
    cout << "? " << x << ' ' << y << endl;
    i64 z;
    cin >> z;
    if (y == z) swap(x, y);
    q.push(x);
    w[x].push_back(y);
  }
  return { q.front(), w[q.front()] };
}

int main() {
  cin >> n;
  vector<i64> a(n);
  iota(begin(a), end(a), 1);
  auto p = f(a);
  cerr << "first: " << p.first << endl;
  auto q = f(p.second);
  cout << "! " << q.first << endl;
  return 0;
}
0