이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const int INF=1e9;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
int n, arr[maxn], ans[maxn], jwb, ans1[maxn], ans2[maxn], p1, p2;
bool udh;
int main() {
ok
cin >> n;
for(int i=1; i<=n; i++) cin >> arr[i];
if(n<=6) {
for(int i=0; i<n; i++) ans[i]=i+1;
do {
cout << "query";
for(int i=0; i<n; i++) cout << " " << ans[i];
cout << endl;
cout.flush();
cin >> jwb;
if(jwb==1) {
if(!udh) {
for(int i=0; i<n; i++) ans1[i]=ans[i];
udh=1;
}
for(int i=0; i<n; i++) ans2[i]=ans[i];
}
} while(next_permutation(ans, ans+n));
cout << "end" << endl;
for(int i=0; i<n; i++) cout << ans1[i] << " ";
cout << endl;
for(int i=0; i<n; i++) cout << ans2[i] << " ";
cout << endl;
cout.flush();
return 0;
}
for(int i=0; i<n; i++) ans[i]=i+1;
cout << "query";
for(int i=0; i<n; i++) cout << " " << ans[i];
cout << endl;
cout.flush();
cin >> jwb;
if(jwb==1) {
for(int i=0; i<n; i++) ans1[i]=i+1;
for(int i=0; i<n; i++) {
for(int j=i+1; j<n; j++) {
swap(ans1[i], ans1[j]);
cout << "query";
for(int k=0; k<n; k++) cout << " " << ans1[k];
cout << endl;
cout.flush();
cin >> jwb;
swap(ans1[i], ans1[j]);
if(jwb==0) {
p1=i;
p2=j;
break;
}
}
if(p1+p2>0) break;
}
int cur=n;
for(int i=0; i<n; i++) {
if(i==p1) {
ans2[i]=cur-1;
ans2[p2]=cur;
cur-=2;
} else if(i!=p2) {
ans2[i]=cur--;
}
}
cout << "end" << endl;
for(int i=0; i<n; i++) cout << ans1[i] << " ";
cout << endl;
for(int i=0; i<n; i++) cout << ans2[i] << " ";
cout << endl;
cout.flush();
return 0;
} else {
for(int i=0; i<n; i++) ans1[n-i-1]=i+1;
for(int i=0; i<n; i++) {
for(int j=i+1; j<n; j++) {
swap(ans1[i], ans1[j]);
cout << "query";
for(int k=0; k<n; k++) cout << " " << ans1[k];
cout << endl;
cout.flush();
cin >> jwb;
swap(ans1[i], ans1[j]);
if(jwb==0) {
p1=i;
p2=j;
break;
}
}
if(p1+p2>0) break;
}
int cur=1;
for(int i=0; i<n; i++) {
if(i==p1) {
ans2[i]=cur+1;
ans2[p2]=cur;
cur+=2;
} else if(i!=p2) {
ans2[i]=cur++;
}
}
cout << "end" << endl;
for(int i=0; i<n; i++) cout << ans2[i] << " ";
cout << endl;
for(int i=0; i<n; i++) cout << ans1[i] << " ";
cout << endl;
cout.flush();
return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |