# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
570620 | patrikpavic2 | Zagonetka (COI18_zagonetka) | C++17 | 108 ms | 416 KiB |
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 <cstdio>
#include <vector>
#include <algorithm>
#define PB push_back
#define X first
#define Y second
using namespace std;
typedef pair < int, int > pii;
const int N = 5050;
int p[N], q[N], l[N], r[N], uz[N], n;
bool pitaj(){
printf("query ");
for(int i = 0;i < n;i++)
printf("%d ", q[i]);
printf("\n"); fflush(stdout);
int x; scanf("%d", &x);
return x;
}
int main(){
scanf("%d", &n);
for(int i = 0;i < n;i++){
scanf("%d", p + i);
q[i] = p[i];
}
for(int i = 0;i < n;i++){
for(int j = q[i] - 1;j >= 1;j--){
if(uz[j]) continue;
vector < pii > vr;
for(int k = i;k < n;k++){
if(q[k] <= q[i] && q[k] >= j)
vr.PB({q[k], k});
}
sort(vr.begin(), vr.end());
for(int i = 0;i + 1 < (int)vr.size();i++){
q[vr[i + 1].Y] = vr[i].X;
}
q[vr[0].Y] = vr.back().X;
if(!pitaj()){
for(pii &tmp : vr)
q[tmp.Y] = tmp.X;
}
}
uz[q[i]] = 1;
}
for(int i = 0;i < n;i++){
l[i] = q[i]; q[i] = p[i];
uz[i + 1] = 0;
}
for(int i = 0;i < n;i++){
for(int j = q[i] + 1;j <= n;j++){
if(uz[j]) continue;
vector < pii > vr;
for(int k = i;k < n;k++){
if(q[k] >= q[i] && q[k] <= j)
vr.PB({q[k], k});
}
sort(vr.begin(), vr.end());
for(int i = 0;i + 1 < (int)vr.size();i++){
q[vr[i].Y] = vr[i + 1].X;
}
q[vr.back().Y] = vr[0].X;
if(!pitaj()){
for(pii &tmp : vr)
q[tmp.Y] = tmp.X;
}
}
uz[q[i]] = 1;
}
printf("end\n");
for(int i = 0;i < n;i++)
printf("%d ", l[i]);
printf("\n");
for(int i = 0;i < n;i++)
printf("%d ", q[i]);
printf("\n");
fflush(stdout);
return 0;
}
Compilation message (stderr)
# | 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... |