結果

問題 No.2496 LCM between Permutations
ユーザー kwm_tkwm_t
提出日時 2023-10-07 11:20:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 2,437 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 207,204 KB
実行使用メモリ 24,396 KB
平均クエリ数 952.76
最終ジャッジ日時 2023-10-07 11:20:46
合計ジャッジ時間 6,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,348 KB
testcase_01 AC 25 ms
24,036 KB
testcase_02 AC 24 ms
24,396 KB
testcase_03 AC 24 ms
23,556 KB
testcase_04 AC 25 ms
24,036 KB
testcase_05 AC 25 ms
23,652 KB
testcase_06 AC 26 ms
24,360 KB
testcase_07 AC 25 ms
24,336 KB
testcase_08 AC 26 ms
23,388 KB
testcase_09 AC 26 ms
24,024 KB
testcase_10 AC 26 ms
23,652 KB
testcase_11 AC 25 ms
23,832 KB
testcase_12 AC 25 ms
23,400 KB
testcase_13 AC 26 ms
24,348 KB
testcase_14 AC 25 ms
23,436 KB
testcase_15 AC 31 ms
23,436 KB
testcase_16 AC 32 ms
24,396 KB
testcase_17 AC 33 ms
24,396 KB
testcase_18 AC 95 ms
24,060 KB
testcase_19 AC 72 ms
24,036 KB
testcase_20 AC 94 ms
24,024 KB
testcase_21 AC 84 ms
23,388 KB
testcase_22 AC 79 ms
23,844 KB
testcase_23 AC 105 ms
23,664 KB
testcase_24 AC 92 ms
23,676 KB
testcase_25 AC 113 ms
23,676 KB
testcase_26 AC 112 ms
24,036 KB
testcase_27 AC 113 ms
23,832 KB
testcase_28 AC 125 ms
24,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint998244353;
//const int mod = 998244353;
//using mint = modint1000000007;
//const int mod = 1000000007;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int local(int u, int v) {
	vector<int>a = { 5,1,3,2,4 };
	vector<int>b = { 4,2,1,3,5 };
	return lcm(a[u], b[v]);
}
auto query(int u, int v, int add = 1) {
	std::cout << "? " << u + add << " " << v + add;
	std::cout << std::endl;
	fflush(stdout);
	//return local(u, v);
	int get; std::cin >> get;
	return get;
}
void answer(std::vector<int>u, std::vector<int>v, int add = 0) {
	std::cout << "!";
	for (int i = 0; i < u.size(); ++i)std::cout << " " << u[i] + add;
	for (int i = 0; i < v.size(); ++i)std::cout << " " << v[i] + add;
	std::cout << std::endl;
	fflush(stdout);
}
std::vector<long long> sieveOfEratosthenes(long long  n = 1000000) {
	std::vector<bool>p(n + 1, true);
	std::vector<long long>ret;
	p[0] = false;
	p[1] = false;
	for (int i = 2; i <= n; ++i) {
		if (!p[i]) continue;
		ret.push_back(i);
		for (int j = 2 * i; j <= n; j += i) p[j] = false;
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	if (1 == n) {
		answer({ 1 }, { 1 });
		return 0;
	}
	auto sieve = sieveOfEratosthenes(n);
	auto prime = sieve.back();
	vector<int>p;
	rep(i, n) {
		auto get = query(i, i);
		if (0 == get % prime)p.push_back(i);
	}
	int pa, pb;
	if (1 != p.size()) {
		auto get = query(p[0], p[1]);
		if (0 == get % prime) {
			pa = p[0], pb = p[1];
		}
		else {
			pa = p[1], pb = p[0];
		}
	}
	else {
		pa = pb = p[0];
	}
	vector<int>a(n), b(n);
	a[pa] = b[pb] = prime;
	rep(i, n) {
		if (i == pa)continue;
		auto get = query(i, pb);
		a[i] = get / prime;
	}
	rep(i, n) {
		if (i == pb)continue;
		auto get = query(pa, i);
		b[i] = get / prime;
	}
	answer(a, b);
	return 0;
}
0