結果
問題 | No.2496 LCM between Permutations |
ユーザー | ococonomy1 |
提出日時 | 2023-10-06 22:46:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 3,613 bytes |
コンパイル時間 | 1,045 ms |
コンパイル使用メモリ | 112,804 KB |
実行使用メモリ | 24,408 KB |
平均クエリ数 | 952.76 |
最終ジャッジ日時 | 2023-10-06 22:46:31 |
合計ジャッジ時間 | 4,535 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
23,640 KB |
testcase_01 | AC | 24 ms
23,856 KB |
testcase_02 | AC | 25 ms
23,664 KB |
testcase_03 | AC | 24 ms
23,640 KB |
testcase_04 | AC | 24 ms
24,024 KB |
testcase_05 | AC | 25 ms
23,676 KB |
testcase_06 | AC | 25 ms
24,036 KB |
testcase_07 | AC | 25 ms
23,556 KB |
testcase_08 | AC | 26 ms
24,060 KB |
testcase_09 | AC | 26 ms
23,988 KB |
testcase_10 | AC | 25 ms
24,024 KB |
testcase_11 | AC | 26 ms
23,664 KB |
testcase_12 | AC | 25 ms
24,396 KB |
testcase_13 | AC | 25 ms
23,400 KB |
testcase_14 | AC | 25 ms
24,036 KB |
testcase_15 | AC | 32 ms
23,376 KB |
testcase_16 | AC | 32 ms
24,408 KB |
testcase_17 | AC | 34 ms
23,436 KB |
testcase_18 | AC | 99 ms
23,436 KB |
testcase_19 | AC | 71 ms
24,276 KB |
testcase_20 | AC | 93 ms
23,556 KB |
testcase_21 | AC | 83 ms
23,676 KB |
testcase_22 | AC | 78 ms
24,036 KB |
testcase_23 | AC | 105 ms
23,628 KB |
testcase_24 | AC | 90 ms
24,264 KB |
testcase_25 | AC | 110 ms
23,664 KB |
testcase_26 | AC | 111 ms
23,412 KB |
testcase_27 | AC | 115 ms
23,424 KB |
testcase_28 | AC | 113 ms
23,880 KB |
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内: main.cpp:87:15: 警告: ‘p’ may be used uninitialized [-Wmaybe-uninitialized] 87 | a[p1] = b[p1] = p; main.cpp:58:9: 備考: ‘p’ はここで定義されています 58 | int p; | ^
ソースコード
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; using lg = long long; using pii = pair<int, int>; using pll = pair<lg, lg>; #define TEST cerr << "TEST" << endl #define AMARI 998244353 // #define AMARI 1000000007 #define TEMOTO ((sizeof(long double) == 16) ? false : true) #define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000) #define el '\n' #define El '\n' //0始まりの添え字で良いよ ありがとう void print_quetion(int i,int j){ cout << '?'; cout << ' ' << i + 1; cout << ' ' << j + 1; cout << '\n'; cout << flush; return; } void print_ans(vector<int> const& a,vector<int> const& b){ cout << '!'; for(int i = 0; i < a.size(); i++)cout << ' ' << a[i]; for(int i = 0; i < b.size(); i++)cout << ' ' << b[i]; cout << '\n'; cout << flush; return; } #define MULTI_TEST_CASE false void solve(void) { int n; cin >> n; if(n == 1){ print_ans({1},{1}); return; } int p; //n以下の最大の素数pを探す for(int i = n; i >= 1; i--){ //iが素数かどうか調べる 時間はたっぷりある bool sosuu = true; for(int j = 2; j * j <= i; j++){ if(i % j == 0){ sosuu = false; break; } } if(sosuu){ p = i; break; } } int p1 = -1,p2 = -1; for(int i = 0; i < n; i++){ print_quetion(i,i); int lcm; cin >> lcm; if(lcm % p == 0){ if(p1 == -1)p1 = i; else p2 = i; } } if(p2 == -1){ //a[p1] = b[p1] = p vector<int> a(n),b(n); a[p1] = b[p1] = p; for(int i = 0; i < n; i++){ if(i == p1)continue; print_quetion(i,p1); int temp; cin >> temp; a[i] = temp / p; } for(int i = 0; i < n; i++){ if(i == p1)continue; print_quetion(p1,i); int temp; cin >> temp; b[i] = temp / p; } print_ans(a,b); return; } print_quetion(p1,p2); int temp; cin >> temp; if(temp == p){ vector<int> a(n),b(n); a[p1] = b[p2] = p; for(int i = 0; i < n; i++){ if(i == p1)continue; print_quetion(i,p2); int t2; cin >> t2; a[i] = t2 / p; } for(int i = 0; i < n; i++){ if(i == p2)continue; print_quetion(p1,i); int t2; cin >> t2; b[i] = t2 / p; } print_ans(a,b); return; } swap(p1,p2); vector<int> a(n),b(n); a[p1] = b[p2] = p; for(int i = 0; i < n; i++){ if(i == p1)continue; print_quetion(i,p2); int t2; cin >> t2; a[i] = t2 / p; } for(int i = 0; i < n; i++){ if(i == p2)continue; print_quetion(p1,i); int t2; cin >> t2; b[i] = t2 / p; } print_ans(a,b); return; } void calc(void) { return; } int main(void) { cin.tie(nullptr); ios::sync_with_stdio(false); calc(); int t = 1; if(MULTI_TEST_CASE) cin >> t; while(t--) { solve(); } return 0; }