This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
int N, A[101], B[101], P[101], Q[101];
bool query()
{
cout << "query";
for (int i = 0; i < N; i++) cout << " " << B[i];
cout << endl;
bool x; cin >> x;
return x;
}
int main()
{
cin >> N;
for (int i = 0; i < N; i++) {cin >> A[i];}
for (int i = 0; i < N; i++)
{
B[i] = A[i];
P[B[i] - 1] = i;
}
for (int i = 1; i < N; i++)
{
for (int j = i - 1; j >= 0; j--)
{
if (P[j + 1] < P[j])
{
swap(B[P[j + 1]], B[P[j]]);
if (query() == 0) {swap(B[P[j + 1]], B[P[j]]); break;}
else swap(P[j + 1], P[j]);
}
else {break;}
}
}
for (int i = 0; i < N; i++)
{
B[i] = A[i];
Q[B[i] - 1] = i;
}
for (int i = 1; i < N; i++)
{
for (int j = i - 1; j >= 0; j--)
{
if (Q[j + 1] > Q[j])
{
swap(B[Q[j + 1]], B[Q[j]]);
if (query() == 0) {swap(B[Q[j + 1]], B[Q[j]]); break;}
else swap(Q[j + 1], Q[j]);
}
else {break;}
}
}
cout << "end" << endl;
for (int i = 0; i < N; i++) {B[P[i]] = i;}
for (int i = 0; i < N; i++) cout << B[i] + 1 << " \n"[i + 1 == N];
for (int i = 0; i < N; i++) {B[Q[i]] = i;}
for (int i = 0; i < N; i++) cout << B[i] + 1 << " \n"[i + 1 == N];
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... |