結果
問題 | No.2496 LCM between Permutations |
ユーザー | KumaTachiRen |
提出日時 | 2023-09-01 01:38:34 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,212 bytes |
コンパイル時間 | 4,248 ms |
コンパイル使用メモリ | 262,608 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 952.83 |
最終ジャッジ日時 | 2024-06-24 04:22:30 |
合計ジャッジ時間 | 8,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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; 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; } }