結果
| 問題 |
No.2496 LCM between Permutations
|
| ユーザー |
|
| 提出日時 | 2023-09-01 01:29:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,208 bytes |
| コンパイル時間 | 4,380 ms |
| コンパイル使用メモリ | 250,136 KB |
| 最終ジャッジ日時 | 2025-02-16 15:56:33 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 4 WA * 5 RE * 19 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
struct Fast {
Fast() {
std::cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(10);
}
} fast;
#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)
int guess(int i, int j) {
cout << "? " << (i + 1) << " " << (j + 1) << endl;
int l;
cin >> l;
return l;
}
int main() {
int n;
cin >> n;
if (n == 1) {
cout << "! 1 1" << endl;
} else {
int p = n / 2 + 1;
for (; true; p++) {
bool ok = true;
for (int d = 2; d * d <= p; d += (d & 1) + 1) ok &= p % d != 0;
if (ok) break;
}
int x = -1, y = -1;
rep(i, 0, n) {
int l = guess(i, i);
if (l == p) {
if (x == -1)
x = i;
else
y = i;
}
}
if (y == -1) {
y = x;
} else {
if (guess(x, y) != p) swap(x, y);
}
vector<int> a(n), b(n);
a[x] = p;
b[y] = p;
rep(i, 0, n) {
if (i != x) a[i] = guess(i, y) / p;
if (i != y) b[i] = guess(x, i) / p;
}
cout << "!";
rep(i, 0, n) cout << " " << a[i];
rep(i, 0, n) cout << " " << b[i];
cout << endl;
}
}