#include <bits/stdc++.h>
using namespace std;
int a, b;
bool debug = false;
bool grad(vector<int>&v){
return (v[a-1] < v[b-1]);
}
bool ask(vector<int>&v){
cout << "query ";
for(auto &x: v) cout << x << " ";
cout << endl;
bool ret;
if(debug) ret = grad(v);
else cin >> ret;
return ret;
}
void st1(int n){
vector<int>v(n);
for(int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
vector<int>mini(n, 1e9), maxi(n, -1);
do{
if(ask(v)){
if(v < mini) mini = v;
if(v > maxi) maxi = v;
}
} while (next_permutation(v.begin(), v.end()));
cout << "end" << endl;
for(auto &x: mini) cout << x << " ";
cout << endl;
for(auto &x: maxi) cout << x << " ";
cout << endl;
}
void st2(int n){
vector<int>v(n);
for(int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
bool asc = ask(v);
if(!asc) reverse(v.begin(), v.end());
int a = -1, b = -1;
for(int i = 0; i < n; i++){
if(b != -1) break;
for(int j = i + 1; j < n; j++){
swap(v[i], v[j]);
bool tmp = ask(v);
swap(v[i], v[j]);
if(!tmp){
b = j;
break;
}
}
}
for(int i = b - 1; i >= 0; i--){
swap(v[b], v[i]);
bool tmp = ask(v);
swap(v[b], v[i]);
if(!tmp){
a = i;
break;
}
}
cout << "end" << endl;
sort(v.begin(), v.end());
int ans[n];
bool mark[n + 1];
memset(ans, -1, sizeof(ans));
memset(mark, 0, sizeof(mark));
if(!asc){
mark[v[a]] = mark[v[a] + 1] = true;
ans[a] = v[a] + 1;
ans[b] = v[a];
}
int j = 0;
for(int i = 0; i < n; i++){
if(ans[i] != -1) continue;
while(mark[v[j]]) j++;
mark[v[j]] = true;
ans[i] = v[j];
j++;
}
for(auto &x: ans) cout << x << " ";
cout << endl;
sort(v.begin(), v.end(), greater<int>());
memset(ans, -1, sizeof(ans));
memset(mark, 0, sizeof(mark));
if(asc){
mark[v[a]] = mark[v[a] - 1] = true;
ans[a] = v[a] - 1;
ans[b] = v[a];
}
j = 0;
for(int i = 0; i < n; i++){
if(ans[i] != -1) continue;
while(mark[v[j]]) j++;
mark[v[j]] = true;
ans[i] = v[j];
j++;
}
for(auto &x: ans) cout << x << " ";
cout << endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
if(debug) cin >> a >> b;
if(n <= 6) st1(n);
else st2(n);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
5 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |