結果

問題 No.850 企業コンテスト2位
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-07-06 10:53:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,698 bytes
コンパイル時間 1,523 ms
コンパイル使用メモリ 166,832 KB
実行使用メモリ 24,336 KB
平均クエリ数 359.64
最終ジャッジ日時 2023-09-23 17:45:57
合計ジャッジ時間 6,711 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,280 KB
testcase_01 AC 29 ms
23,964 KB
testcase_02 AC 27 ms
23,340 KB
testcase_03 AC 27 ms
23,568 KB
testcase_04 AC 27 ms
23,880 KB
testcase_05 AC 27 ms
23,484 KB
testcase_06 AC 27 ms
24,276 KB
testcase_07 AC 34 ms
23,556 KB
testcase_08 AC 38 ms
23,880 KB
testcase_09 AC 37 ms
24,132 KB
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 AC 27 ms
24,336 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int ask(int, int)’ 内:
main.cpp:70:17: 警告: ‘a’ may be used uninitialized [-Wmaybe-uninitialized]
   70 |                 if (a < b) return x;
      |                 ^~
main.cpp:60:21: 備考: ‘a’ はここで定義されています
   60 |                 int a, b;
      |                     ^
main.cpp:70:17: 警告: ‘b’ may be used uninitialized [-Wmaybe-uninitialized]
   70 |                 if (a < b) return x;
      |                 ^~
main.cpp:60:24: 備考: ‘b’ はここで定義されています
   60 |                 int a, b;
      |                        ^

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int getrandmax() {
    static uint32_t y = time(NULL);
    y ^= (y << 13); y ^= (y >> 17);
    y ^= (y << 5);
    return abs((int)y);
}
int getrand(int l, int r) { // [l, r]
    return getrandmax() % (r - l + 1) + l;
}
vector<int> makePermutation(int n, int loop = 101010) {
	vector<int> v(n);
	rep(i, 0, n) v[i] = i + 1;
	rep(j, 0, loop) {
		int a = getrand(0, n - 1);
		int b = getrand(0, n - 1);
		swap(v[a], v[b]);
	}
	return v;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
int forDebug[] = { -1, 2,4,1,3 };
bool isDebug = false;
int ask(int x, int y) {
	if (isDebug) {
		int a, b;
		rep(i, 1, N + 1) if (forDebug[i] == x) {
			a = i;
			break;
		}
		rep(i, 1, N + 1) if (forDebug[i] == y) {
			b = i;
			break;
		}

		if (a < b) return x;
		return y;
	}

	printf("? %d %d\n", x, y);
	fflush(stdout);
	int res; cin >> res;
	return res;
}
void answer(int x) {
	printf("! %d\n", x);
	fflush(stdout);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;

	auto per = makePermutation(N);

	int first, second;
	if (ask(per[0], per[1]) == per[0]) first = per[0], second = per[1];
	else first = per[1], second = per[0];

	rep(i, 2, N) {
		int x = per[i];

		if (ask(first, x) == first) {
			if (ask(second, x) == x) {
				second = x;
			}
		}
		else {
			second = first;
			first = x;
		}
	}

	answer(second);
}




0