結果

問題 No.2577 Simple Permutation Guess
ユーザー anago-pie
提出日時 2023-12-13 23:05:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 384 ms / 2,000 ms
コード長 1,781 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 184,440 KB
実行使用メモリ 275,512 KB
平均クエリ数 251.86
最終ジャッジ日時 2024-09-27 05:32:36
合計ジャッジ時間 17,007 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 111
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 0
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = atan2(0, -1);
#include <time.h>
#include <chrono>

int main() {

	int n;
	cin >> n;
	vector<int> list(n + 1);
	rep(i, n + 1) {
		list[i] = i + 1;
	}
	vector<int> ans;
	set<int> res;
	rep(i, n) {
		res.insert(i + 1);
	}

	if (n <= 10) {
		vector<vector<int>> all;
		vector<int> v(n);
		rep(i, n) {
			v[i] = i + 1;
		}
		do {
			all.push_back(v);
		} while (next_permutation(v.begin(), v.end()));

		int l = 0, r = all.size();
		while (r > l + 1) {
			int mid = (l + r) / 2;
			cout << "? ";
			for (int x : all[mid]) {
				cout << x << " ";
			}
			cout << endl;

			int ret;
			cin >> ret;
			if (ret == 0) {
				r = mid;
			}
			else {
				l = mid;
			}
		}

		cout << "! ";
		for (int x : all[l]) {
			cout << x << " ";
		}
		cout << endl;
		return 0;
	}

	//int cnt = 0;
	rep(i, n) {
		int l = i, r = n;
		while (r > l + 1) {

			//Query
			int mid = (l + r) / 2;
			cout << "? ";
			for (int x : ans) {
				cout << x << " ";
			}
			cout << list[mid] << " ";
			for (int x : res) {
				if (x != list[mid]) {
					cout << x << " ";
				}
			}
			cout << endl;
			//cnt++;

			int ret;
			cin >> ret;
			if (ret == 0) {
				r = mid;
			}
			if (ret == 1) {
				l = mid;
			}
		}

		ans.push_back(list[l]);
		res.erase(list[l]);
		list[l] = -1;
		sort(list.begin(), list.end());
	}

	cout << "! ";
	for (int x : ans) {
		cout << x << " ";
	}
	cout << endl;
	/*
	cout << "Query=" << cnt << endl;
	cout << "Limit=" << floor(floor((n - 1) * log2(n)) - (double)(n - 1) / 2 + 1) << endl;
	*/
}
0