結果
問題 | No.2496 LCM between Permutations |
ユーザー | Dispersion-atc |
提出日時 | 2024-04-02 23:53:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,907 bytes |
コンパイル時間 | 2,529 ms |
コンパイル使用メモリ | 211,324 KB |
実行使用メモリ | 25,580 KB |
平均クエリ数 | 953.28 |
最終ジャッジ日時 | 2024-09-30 23:25:32 |
合計ジャッジ時間 | 7,932 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
25,196 KB |
testcase_01 | AC | 22 ms
24,836 KB |
testcase_02 | AC | 22 ms
24,964 KB |
testcase_03 | RE | - |
testcase_04 | AC | 21 ms
25,220 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 23 ms
24,580 KB |
testcase_09 | RE | - |
testcase_10 | AC | 23 ms
24,580 KB |
testcase_11 | RE | - |
testcase_12 | AC | 22 ms
24,964 KB |
testcase_13 | AC | 25 ms
24,580 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | AC | 31 ms
24,556 KB |
testcase_17 | AC | 35 ms
24,556 KB |
testcase_18 | AC | 107 ms
25,220 KB |
testcase_19 | AC | 70 ms
25,220 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 85 ms
25,220 KB |
testcase_23 | RE | - |
testcase_24 | AC | 102 ms
24,580 KB |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (a % b == 0) {return b;} else {return gcd(b, a % b);} } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll query(ll i, ll j) { cout << "?" << " " << i+1 << " " << j+1 << endl; ll X; cin >> X; return X; } void output(vector<ll> &A, vector<ll> &B) { assert(A.size() == B.size()); cout << "!" << " "; for (auto a : A) cout << a << " "; for (auto b : B) cout << b << " "; cout << endl; return; } const ll nmax = 1010; bool isprime[nmax]; const ll INF = 1e18; void init() { for (int i = 2; i < nmax; ++i) { bool flg = true; for (int j = 2; j * j <= i; ++j) { if (i % j == 0) flg = false; } isprime[i] = flg; } return; } int main() { init(); ll N; cin >> N; if (N <= 2) { if (N == 1) { cout << "!" << " " << 1 << " " << 1 << endl; return 0; } else { ll q00 = query(0, 0); ll q01 = query(0, 1); ll q10 = query(1, 0); ll q11 = query(1, 1); vector<ll> A(N), B(N); { if (q00 == q01) A[0] = 2; else A[0] = 1; A[1] = 3 - A[0]; } { if (q00 == q10) B[0] = 2; else B[0] = 1; B[1] = 3 - B[0]; } output(A, B); return 0; } return 0; } ll a0 = INF, p = -1; ll bp = -1; { vector<ll> b(N); for (int i = 0; i < N; ++i) b[i] = query(0, i); for (auto bb : b) chmin(a0, bb); for (int n = 1; n <= N; ++n) { if (isprime[n] && gcd(a0, n) == 1) p = n; } assert(p != -1); ll lc = lcm(a0, p); for (int i = 0; i < N; ++i) { if (b[i] == lc) bp = i; } } cerr << p << endl; vector<ll> A(N), B(N); { vector<ll> veca(N); vector<ll> pid; for (int i = 0; i < N; ++i) { ll a = query(i, bp); veca[i] = a; for (int j = 1; j <= N; ++j) { if (lcm(j, p) == a) A[i] = j; } if (a == p) pid.emplace_back(i); } vector<ll> vecb(N); assert(pid.size() > 0); ll ap = pid[0]; bool isone = false; for (int i = 0; i < N; ++i) { vecb[i] = query(ap, i); if (vecb[i] == 1) isone = true; } if (isone) { A[ap] = 1; for (int i = 0; i < N; ++i) { B[i] = vecb[i]; } } else { A[ap] = p; for (int i = 0; i < N; ++i) { ll b = vecb[i]; for (int j = 1; j <= N; ++j) { if (lcm(p, j) == b) B[i] = j; } if (b == p) { if (i == bp) B[i] = p; else B[i] = 1; } } } } vector<ll> copya = A, copyb = B; sort(copya.begin(), copya.end()); sort(copyb.begin(), copyb.end()); for (int i = 0; i < N; ++i) { // cout << i << " " << copya[i] << " " << copyb[i] << endl; assert(copya[i] == i+1); assert(copyb[i] == i+1); } output(A, B); return 0; }