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 <stdio.h>
#include <string.h>
#define N 100
int n;
int query(int *ii) {
static int pp[N];
int i, x;
printf("query");
for (i = 0; i < n; i++)
pp[ii[i]] = i + 1;
for (i = 0; i < n; i++)
printf(" %d", pp[i]);
printf("\n"), fflush(stdout);
scanf("%d", &x);
return x;
}
char adj[N][N]; int dd[N];
int main() {
static int ii[N], aa[N], bb[N];
int i, j, k, a, b, c;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a), a--;
ii[a] = i;
}
for (b = 1; b < n; b++)
for (a = b - 1, c = b; a >= 0; a--) {
int tmp;
tmp = ii[a];
for (k = a; k < c; k++)
ii[k] = ii[k + 1];
ii[c] = tmp;
if (!query(ii)) {
tmp = ii[c];
for (k = c; k > a; k--)
ii[k] = ii[k - 1];
ii[a] = tmp;
adj[ii[a]][ii[c]] = 1;
} else
c--;
}
for (i = 0; i < n; i++) {
dd[i] = 0;
for (j = 0; j < n; j++)
if (adj[i][j])
dd[i]++;
}
for (a = n - 1; a >= 0; a--) {
for (j = n - 1; j >= 0; j--)
if (dd[j] == 0)
break;
dd[j] = -1, aa[j] = a;
for (i = 0; i < n; i++)
if (adj[i][j])
dd[i]--;
}
for (j = 0; j < n; j++) {
dd[j] = 0;
for (i = 0; i < n; i++)
if (adj[i][j])
dd[j]++;
}
for (a = 0; a < n; a++) {
for (i = n - 1; i >= 0; i--)
if (dd[i] == 0)
break;
dd[i] = -1, bb[i] = a;
for (j = 0; j < n; j++)
if (adj[i][j])
dd[j]--;
}
printf("end\n");
for (i = 0; i < n; i++)
printf("%d ", aa[i] + 1);
printf("\n");
for (i = 0; i < n; i++)
printf("%d ", bb[i] + 1);
printf("\n");
return 0;
}
Compilation message (stderr)
zagonetka.c: In function 'query':
zagonetka.c:18:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &x);
| ^~~~~~~~~~~~~~~
zagonetka.c: In function 'main':
zagonetka.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
zagonetka.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d", &a), a--;
| ^~~~~~~~~~~~~~~
# | 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... |