結果
問題 | No.2496 LCM between Permutations |
ユーザー |
|
提出日時 | 2023-09-01 01:38:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 1,212 bytes |
コンパイル時間 | 3,506 ms |
コンパイル使用メモリ | 252,252 KB |
最終ジャッジ日時 | 2025-02-16 15:56:53 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#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 == 0) {if (x == -1)x = i;elsey = 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;}}