結果
問題 | No.2496 LCM between Permutations |
ユーザー | Astral__ |
提出日時 | 2023-10-06 22:16:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 9,315 bytes |
コンパイル時間 | 2,681 ms |
コンパイル使用メモリ | 219,928 KB |
実行使用メモリ | 25,580 KB |
平均クエリ数 | 773.45 |
最終ジャッジ日時 | 2024-07-26 16:30:06 |
合計ジャッジ時間 | 6,432 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
25,196 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 26 ms
24,836 KB |
testcase_04 | AC | 24 ms
24,964 KB |
testcase_05 | AC | 24 ms
25,220 KB |
testcase_06 | AC | 24 ms
24,836 KB |
testcase_07 | AC | 25 ms
24,836 KB |
testcase_08 | AC | 25 ms
24,952 KB |
testcase_09 | AC | 24 ms
24,964 KB |
testcase_10 | AC | 26 ms
25,220 KB |
testcase_11 | AC | 24 ms
25,220 KB |
testcase_12 | AC | 24 ms
24,836 KB |
testcase_13 | AC | 25 ms
24,964 KB |
testcase_14 | AC | 24 ms
24,836 KB |
testcase_15 | AC | 29 ms
24,940 KB |
testcase_16 | AC | 30 ms
25,580 KB |
testcase_17 | AC | 33 ms
24,556 KB |
testcase_18 | AC | 81 ms
25,220 KB |
testcase_19 | AC | 59 ms
24,836 KB |
testcase_20 | AC | 93 ms
25,220 KB |
testcase_21 | AC | 72 ms
24,964 KB |
testcase_22 | AC | 66 ms
25,220 KB |
testcase_23 | AC | 83 ms
25,220 KB |
testcase_24 | AC | 71 ms
25,220 KB |
testcase_25 | AC | 86 ms
24,964 KB |
testcase_26 | AC | 106 ms
24,556 KB |
testcase_27 | AC | 98 ms
24,940 KB |
testcase_28 | AC | 97 ms
24,812 KB |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:318:9: warning: 'pre' may be used uninitialized [-Wmaybe-uninitialized] 318 | B.at(pre) = p; | ~~~~^~~~~ main.cpp:288:8: note: 'pre' was declared here 288 | ll pre; | ^~~ main.cpp:302:23: warning: 'tmp' may be used uninitialized [-Wmaybe-uninitialized] 302 | rres.push_back(P(a(i, tmp), i)); | ~^~~~~~~~ main.cpp:287:8: note: 'tmp' was declared here 287 | ll tmp; | ^~~ main.cpp:254:9: warning: 'pre' may be used uninitialized [-Wmaybe-uninitialized] 254 | A.at(pre) = p; | ~~~~^~~~~ main.cpp:219:6: note: 'pre' was declared here 219 | ll pre; | ^~~ main.cpp:237:23: warning: 'tmp' may be used uninitialized [-Wmaybe-uninitialized] 237 | rres.push_back(P(a(tmp, i), i)); | ~^~~~~~~~ main.cpp:218:6: note: 'tmp' was declared here 218 | ll tmp; | ^~~
ソースコード
#include<bits/stdc++.h> #define PPque priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> #define Pque priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> #define pque priority_queue<ll, vector<ll>, greater<ll>> #define umap unordered_map #define uset unordered_set #define rep(i, s, f) for(ll i = s; i <= f; i++) #define per(i, s, f) for(ll i = s; i >= f; i--) #define all0(x) (x).begin() ,(x).end() #define all(x) (x).begin() + 1, (x).end() #define vvvvl vector<vvvl> #define vvvi vector<vector<vector<int>>> #define vvvl vector<vector<vector<ll>>> #define vvvc vector<vector<vector<char>>> #define vvvd vector<vector<vector<double>>> #define vvvm vector<vector<vector<mint>>> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vvs vector<vector<string>> #define vvc vector<vector<char>> #define vvp vector<vector<pair<ll, ll>>> #define vvb vector<vector<bool>> #define vvd vector<vector<double>> #define vvm vector<vector<mint>> #define vp vector<pair<ll, ll>> #define vi vector<int> #define vl vector<ll> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vd vector<double> #define vm vector<mint> #define P pair<ll, ll> #define TU tuple<ll, ll, ll> #define rrr(l, r) mt()%(r-l+1)+l #define ENDL '\n' #define ull unsigned long long typedef long long ll; using namespace std; //////////////////////////////////////////////////////////////////////////////////////////////////////////// //これが本当の組み込み関数ってね(笑) template <typename T> T or_less(vector<T> &A, T x) { //x以下で最大要素の添字 前提: sort済み 存在しない: -1 return distance(A.begin(), upper_bound(A.begin(), A.end(), x)-1); } template <typename T> T under(vector<T> &A, T x) { //x未満の最大要素の添字 前提: sort済み 存在しない: -1 return distance(A.begin(), lower_bound(A.begin(), A.end(), x)-1); } template <typename T> T or_more(vector<T> &A, T x) { //x以上で最小要素の添字 前提: sort済み 存在しない: N . //distanceのA.beginは添字を出すために常にA.begin() NG: A.begin() + 1 return distance(A.begin(), lower_bound(A.begin(), A.end(), x)); } template <typename T> T over(vector<T> &A, T x) { //xより大きい最小要素の添字前提: sort済み 存在しない: N return distance(A.begin(), upper_bound(A.begin(), A.end(), x)); } void compress(vector<ll> &A) {//小さい順に順位、大きい順にしたいならreverseはNG最後に変換 //重複無し //最初は番兵 vector<ll> temp = A; sort(temp.begin()+1, temp.end()); temp.erase(unique(temp.begin()+1, temp.end()), temp.end()); for (int i = 1; i <= int(A.size()-1); i++) { A.at(i) = distance(temp.begin(), lower_bound(temp.begin()+1, temp.end(), A.at(i))); } } template <typename T> void UNIQUE(vector<T> &A) { sort(all0(A)); return A.erase(unique(A.begin(), A.end()), A.end()); } template <typename T> void rev90(vector<vector<T>> &A, int indexed = 1) { reverse(A.begin() + indexed, A.end()); int n = A.size(); rep(i, indexed, n-1) { rep(j, i+1, n-1) { swap(A.at(i).at(j), A.at(j).at(i)); } } } void chmin(ll &a, ll b) { a = min(a, b); } void chmax(ll &a, ll b) { a = max(a, b); } ////////////////////////////////////////////////////////////////////// //数学系 /////////////////////////////////////////////////////////////////////// ll round(ll x, ll i) {return ll(x + 5 * pow(10, i-1))/ll(pow(10, i)) * ll(pow(10, i));} vp insu_bunkai(ll N) { vp res; for (int i = 2; i * i <= N; i++) { ll cnt = 0; while(N % i == 0) { cnt++; N /= i; } if(cnt != 0) res.push_back(P(i, cnt)); } if(N != 1) res.push_back(P(N, 1)); return res; } ll extgcd (ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1;y = 0;return a;} ll d = extgcd(b, a%b, y, x); y -= a/b * x; return d; } template <typename T> T ceil(T a, T b) { assert(b != 0); if(a % b == 0) return a / b; if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b + 1; else return a / b; } template <typename T> T floor(T a, T b) { assert(b != 0); if(a % b == 0) return a / b; if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b; else return a/b - 1; } ll modpow(ll x, ll y) { const ll mod = 9223372036854775807LL; if(x > mod) x %= mod; if(y == 0) return 1; ll res = modpow(x, y >> 1); res = res * res % mod; if(y & 1) res *= x, res %= mod; return res; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //グローバル変数を置くところ(情報工学意識高め) //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") const ll int_max = 1001001001; const ll ll_max = 1001001001001001001LL; const double pi = 3.141592653589793; vl dx{0, 1, 0, -1, 0, 1, 1, -1, -1}; // (番兵) → ↓ ← ↑ ※ 右から時計回り vl dy{0, 0, -1, 0, 1, 1, -1, -1, 1}; //const ll mod = 1000000007; //const ll mod = 998244353; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// vector<ll> Exhurui(ll N) { vector<ll> sosu; ll Max = sqrt(N); vector<int> hantei(N+1, 1); hantei.at(1) = 0; for (int i = 2; i <= Max; i++) { if (hantei.at(i) == 1) { for (int j = 2; j * i <= N; j++) { hantei.at(j*i) = 0; } } } for (int i = 2; i <= N; i++) { if (hantei.at(i) == 1) { sosu.push_back(i); } } return sosu; } void solve() { ll N; cin >> N; auto primes = Exhurui(N); ll p = primes.back();//こいつで聞けばわかる auto a = [](ll a, ll b) { cout << "? " << a << " " << b << endl; ll res; cin >> res; return res; }; ll idx = 1; bool aaa = false; for( ; idx <= N; idx++) { cout <<"? " << 1 << " " << idx << endl; ll res; cin >> res; if(res % p == 0) { if(idx == 1) { ll res2 = a(1, 2); if(res2 % p == 0) { aaa = true; } else { break; } } else { break; } } } //if(aaa) A[1]が p //else B[idx]が p ここまでN回以下 if(!aaa) { //Bのbiggest prime idxがわかった vl A(N+1, -1); vl B(N+1, -1); B[idx] = p; ll tmp; ll pre; rep(i, 1, N) { cout << "? " << i << " " << idx << endl; ll res; cin >> res; A.at(i) = res / p; if(A.at(i) == 1) { pre = tmp; tmp = i; } } //2N回 //A[tmp]は今1 or pなので、それを特定する vp rres; rep(i, 1, 3) { if(i == idx) continue; rres.push_back(P(a(tmp, i), i)); if(rres.size() >= 2) break; } //2N + 2回 if(rres.at(0).first % p == 0 && rres.at(1).first % p == 0) { //A[tmp] = p A.at(tmp) = p; tmp = pre; auto [r1, i1] = rres.at(0); B.at(i1) = r1 / p; auto [r2, i2] = rres.at(1); B.at(i2) = r2 / p; } else { //A[tmp] = 1 A.at(pre) = p; auto [r1, i1] = rres.at(0); B.at(i1) = r1; auto [r2, i2] = rres.at(1); B.at(i2) = r2; } rep(i, 1, N) { if(B.at(i) != -1) continue; cout << "? " << tmp << " " << i << endl; ll res; cin >> res; //(1, B.at(i)) または (p, B.at(i)) B.at(i) = res; } cout <<"! "; rep(i, 1, N) cout << A.at(i) << " "; rep(i, 1, N) cout << B.at(i) << " "; } else { vl A(N+1, -1); vl B(N+1, -1); A.at(1) = p; //N回質問済み ll tmp; ll pre; rep(i, 1, N) { B.at(i) = a(1, i) / p; if(B.at(i) == 1) { pre = tmp; tmp = i; } } //2N回 //B[tmp]は今1 or pなので、それを特定する vp rres; rep(i, 2, 3) { rres.push_back(P(a(i, tmp), i)); } //2N + 2回 if(rres.at(0).first % p == 0 && rres.at(1).first % p == 0) { //B[tmp] = p B.at(tmp) = p; tmp = pre; auto [r1, i1] = rres.at(0); A.at(i1) = r1 / p; auto [r2, i2] = rres.at(1); A.at(i2) = r2 / p; } else { //B[tmp] = 1 B.at(pre) = p; auto [r1, i1] = rres.at(0); A.at(i1) = r1; auto [r2, i2] = rres.at(1); A.at(i2) = r2; } rep(i, 1, N) { if(A.at(i) != -1) continue; cout << "? " << i << " " << tmp << endl; ll res; cin >> res; //(1, B.at(i)) または (p, B.at(i)) A.at(i) = res; } cout <<"! "; rep(i, 1, N) cout << A.at(i) << " "; rep(i, 1, N) cout << B.at(i) << " "; } exit(0); } //座標を2で割った時の”切り捨て側(左側)”を求めるには 誤:(x / 2) マイナスの時!!! 正:floor<ll>(x, 2); //stringでの数字の下から1桁目は 正:S.at(N-1) 誤:S.at(0) //if(S.at(i) == 1) ← charなのに1...? // modは取りましたか...?(´・ω・`) //sortの比較関数は、 a == b ならば falseを返す必要がある(そうで無いとRE) int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); ll T = 1; //cin >> T; rep(i, 1, T) { solve(); } return 0; }