結果
問題 | No.2496 LCM between Permutations |
ユーザー | Kude |
提出日時 | 2023-10-06 23:27:14 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,999 bytes |
コンパイル時間 | 3,265 ms |
コンパイル使用メモリ | 278,700 KB |
実行使用メモリ | 28,356 KB |
平均クエリ数 | 720.28 |
最終ジャッジ日時 | 2024-07-26 17:08:03 |
合計ジャッジ時間 | 6,156 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
27,848 KB |
testcase_01 | AC | 27 ms
27,984 KB |
testcase_02 | AC | 28 ms
27,616 KB |
testcase_03 | AC | 27 ms
28,100 KB |
testcase_04 | AC | 27 ms
27,972 KB |
testcase_05 | AC | 27 ms
28,100 KB |
testcase_06 | AC | 27 ms
27,684 KB |
testcase_07 | AC | 27 ms
27,660 KB |
testcase_08 | AC | 27 ms
27,672 KB |
testcase_09 | AC | 27 ms
27,772 KB |
testcase_10 | AC | 26 ms
27,916 KB |
testcase_11 | AC | 27 ms
28,356 KB |
testcase_12 | AC | 26 ms
28,048 KB |
testcase_13 | AC | 26 ms
27,904 KB |
testcase_14 | AC | 27 ms
27,900 KB |
testcase_15 | AC | 30 ms
28,128 KB |
testcase_16 | AC | 31 ms
27,880 KB |
testcase_17 | AC | 38 ms
27,836 KB |
testcase_18 | AC | 81 ms
28,056 KB |
testcase_19 | AC | 58 ms
27,904 KB |
testcase_20 | AC | 74 ms
27,892 KB |
testcase_21 | AC | 70 ms
27,660 KB |
testcase_22 | AC | 66 ms
28,136 KB |
testcase_23 | AC | 83 ms
28,056 KB |
testcase_24 | AC | 72 ms
27,776 KB |
testcase_25 | AC | 83 ms
27,872 KB |
testcase_26 | AC | 98 ms
27,596 KB |
testcase_27 | AC | 94 ms
27,552 KB |
testcase_28 | AC | 93 ms
28,072 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; pair<vector<int>, vector<int>> primes_lpf(const int n) { vector<int> primes; primes.reserve(n / 10); vector<int> lpf(n + 1); for (int i = 2; i <= n; i += 2) lpf[i] = 2; for (int i = 3; i <= n; i += 6) lpf[i] = 3; if (2 <= n) primes.push_back(2); if (3 <= n) primes.push_back(3); // 5 * x <= n, x <= floor(n / 5) const int n5 = n / 5; int x = 5; char add_next = 2; for (; x <= n5; x += add_next, add_next ^= 2 ^ 4) { int px = lpf[x]; if (px == 0) { lpf[x] = px = x; primes.push_back(x); } for (int i = 2;; ++i) { int q = primes[i]; int y = q * x; if (y > n) break; lpf[y] = q; if (q == px) break; } } for (; x <= n; x += add_next, add_next ^= 2 ^ 4) { if (lpf[x] == 0) { lpf[x] = x; primes.push_back(x); } } return {move(primes), move(lpf)}; } constexpr int PSIZE = 1000000; auto [primes, lpf] = primes_lpf(PSIZE); int memo[1010][1010]; } int main() { ios::sync_with_stdio(false); cin.tie(0); memset(memo, -1, sizeof(memo)); int n; cin >> n; bool flip = false; auto ask = [&](int i, int j) { if (flip) swap(i, j); if (memo[i][j] != -1) return memo[i][j]; cout << "? " << i + 1 << ' ' << j + 1 << endl; int res; cin >> res; return memo[i][j] = res; }; auto answer = [&](VI a, VI b) { if (flip) swap(a, b); cout << "!"; for (int x : a) cout << ' ' << x; for (int x : b) cout << ' ' << x; cout << endl; }; if (n == 1) { answer({1}, {1}); return 0; } int pmx = *prev(upper_bound(all(primes), n)); int ip = -1, jp = -1; rep(i, n) { if (i == n - 1) { ip = jp = n - 1; break; } int r = ask(i, i); if (r % pmx == 0) { if (ask(i, i + 1) % pmx == 0) { ip = i; } else { jp = i; } break; } } flip = ip == -1; if (flip) swap(ip, jp); VI a(n), b(n), oneb; rep(j, n) { b[j] = ask(ip, j) / pmx; if (b[j] == 1) oneb.emplace_back(j); } assert(oneb.size() == 2); int i_test = ip == 0 ? 1 : ip - 1; int j1; if (ask(i_test, oneb[0]) % pmx == 0) { b[oneb[0]] = pmx; j1 = oneb[1]; } else { b[oneb[1]] = pmx; j1 = oneb[0]; } rep(i, n) a[i] = ask(i, j1); answer(a, b); }