結果
問題 | No.2496 LCM between Permutations |
ユーザー | bortik |
提出日時 | 2023-10-06 23:42:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 3,274 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 207,584 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 953.86 |
最終ジャッジ日時 | 2024-07-26 17:19:49 |
合計ジャッジ時間 | 5,913 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
25,196 KB |
testcase_01 | AC | 27 ms
25,220 KB |
testcase_02 | AC | 24 ms
25,232 KB |
testcase_03 | AC | 23 ms
24,836 KB |
testcase_04 | AC | 25 ms
24,836 KB |
testcase_05 | AC | 25 ms
24,580 KB |
testcase_06 | AC | 24 ms
25,220 KB |
testcase_07 | AC | 25 ms
24,964 KB |
testcase_08 | AC | 26 ms
25,220 KB |
testcase_09 | AC | 25 ms
25,604 KB |
testcase_10 | AC | 25 ms
24,964 KB |
testcase_11 | AC | 24 ms
25,348 KB |
testcase_12 | AC | 24 ms
24,836 KB |
testcase_13 | AC | 24 ms
24,836 KB |
testcase_14 | AC | 24 ms
25,220 KB |
testcase_15 | AC | 30 ms
25,324 KB |
testcase_16 | AC | 34 ms
24,812 KB |
testcase_17 | AC | 33 ms
24,812 KB |
testcase_18 | AC | 90 ms
25,220 KB |
testcase_19 | AC | 69 ms
24,964 KB |
testcase_20 | AC | 93 ms
25,220 KB |
testcase_21 | AC | 81 ms
25,220 KB |
testcase_22 | AC | 92 ms
25,220 KB |
testcase_23 | AC | 104 ms
25,220 KB |
testcase_24 | AC | 90 ms
25,220 KB |
testcase_25 | AC | 112 ms
25,220 KB |
testcase_26 | AC | 113 ms
25,196 KB |
testcase_27 | AC | 111 ms
25,196 KB |
testcase_28 | AC | 112 ms
25,196 KB |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:64:26: warning: 'p' may be used uninitialized [-Wmaybe-uninitialized] 64 | B[i] = p; main.cpp:23:9: note: 'p' was declared here 23 | int p; | ^ main.cpp:45:5: warning: 'iA' may be used uninitialized [-Wmaybe-uninitialized] 45 | if(iA != 0){ | ^~ main.cpp:32:9: note: 'iA' was declared here 32 | int iA, iB = 0; | ^~
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--) bool isprime(int num){ if(num < 2) return false; for(int i = 2; i <= int(sqrt(num)); i++){ if( num % i == 0) return false; } return true; } void solve(){ int n; cin >> n; if(n == 1){ cout << "! 1 1" << endl; return; } int p; rrep(i, n, 1){ if(isprime(i)){ p = i; break; } } int prev = 1; int s = 1; int iA, iB = 0; rep(i,1,n+1){ cout << "? " << i << " " << 1 << endl; int cur; cin >> cur; if(cur % p == 0 && prev % p != 0){ iA = i; } else if(prev % p == 0 && cur % p == 0){ iB = 1; iA = 0; } prev = cur; } vector<int> A(n+1, 0), B(n+1, 0); if(iA != 0){ int c = 0; A[iA] = p; rep(i,1,n+1){ cout << "? " << iA << " " << i << endl; int cur; cin >> cur; B[i] = cur / p; if(cur == p){ if(c == 0){ cout << "? " << (iA)%n + 1 << " " << i << endl; cin >> cur; if(cur % p == 0){ c = 1; B[i] = p; iB = i; } else { c = 2; } } else if(c == 2){ B[i] = p; iB = i; c = 1; } } } rep(i,1,iA){ cout << "? " << i << " " << iB << endl; int cur; cin >> cur; A[i] = cur / p; } rep(i,iA+1,n+1){ cout << "? " << i << " " << iB << endl; int cur; cin >> cur; A[i] = cur / p; } } else { int c = 0; B[iB] = p; rep(i,1,n+1){ cout << "? " << i << " " << iB << endl; int cur; cin >> cur; A[i] = cur / p; if(cur == p){ if(c == 0){ cout << "? " << i << " " << (iB)%n + 1 << endl; cin >> cur; if(cur % p == 0){ c = 1; A[i] = p; iA = i; } else { c = 2; } } else if(c == 2){ A[i] = p; iA = i; c = 1; } } } rep(i,1,iB){ cout << "? " << iA << " " << i << endl; int cur; cin >> cur; B[i] = cur / p; } rep(i,iB+1,n+1){ cout << "? " << iA << " " << i << endl; int cur; cin >> cur; B[i] = cur / p; } } cout << "! "; rep(i, 1, n+1) cout << A[i] << " "; rep(i, 1, n+1) cout << B[i] << " "; cout << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; rep(i,0,t) solve(); return 0; }