結果
| 問題 |
No.2496 LCM between Permutations
|
| コンテスト | |
| ユーザー |
ococonomy1
|
| 提出日時 | 2023-10-06 22:46:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 111 ms / 2,000 ms |
| コード長 | 3,613 bytes |
| コンパイル時間 | 1,075 ms |
| コンパイル使用メモリ | 110,536 KB |
| 最終ジャッジ日時 | 2025-02-17 05:23:48 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:87:15: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
87 | a[p1] = b[p1] = p;
main.cpp:58:9: note: ‘p’ was declared here
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;
}
ococonomy1