QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740873 | #9432. Permutation | Yansuan_HCl | RE | 0ms | 0kb | C++14 | 2.1kb | 2024-11-13 11:58:47 | 2024-11-13 11:58:47 |
answer
#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;
#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
for (; !IC; GC) f |= c == '-';
for (; IC; GC) x = x * 10 + c - 48;
if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e, v) if (!(e)) { meow("AF@%d\n", __LINE__ ); exit(v); }
#define vc vector
#define eb emplace_back
#define pb push_back
const int N = 1003;
int n, a[N], p[N];
int q[N];
int ask() {
printf("0");
U (i, 1, n) printf(" %d", q[i]);
puts(""); fflush(stdout);
int x; rd(x);
return x;
}
void report() {
printf("1");
U (i, 1, n) printf(" %d", p[i]);
puts(""); fflush(stdout);
exit(0);
}
mt19937 rng(114514);
int b[N];
void solve(int l, int r) {
if (l == r) { p[l] = a[l]; return; }
shuffle(a + l, a + r + 1, rng);
U (i, 1, n) q[i] = a[l];
int mid((l + r) >> 1), x = l, y = mid + 1;
for (int i = l, j; i <= r; i = j + 1) {
j = i + 1; int las = 1;
do {
if (j > r) break;
U (k, l, mid) q[k] = a[i];
U (k, mid + 1, r) q[k] = a[j];
las = ask();
} while ((las == 1) && ++j);
if (j > r) {
// 要么 i 在左边,剩下的全在右边
// 要么 i 在右边,剩下的全在左边
if (i == r - 1) {
assert(0); // 要么两个都对,要么两个都不对
} else {
if (x == mid) {
b[x++] = a[i];
U (k, i + 1, j - 1) b[y++] = a[k];
} else {
b[y++] = a[i];
U (k, i + 1, j - 1) b[x++] = a[k];
}
}
} else if (las == 0) {
// i 在右边
b[y++] = a[i];
b[x++] = a[j];
U (k, i + 1, j - 1) b[y++] = a[k];
} else if (las == 2) {
// i 在左边
b[x++] = a[i];
b[y++] = a[j];
U (k, i + 1, j - 1) b[x++] = a[k];
}
}
U (i, l, r) a[i] = b[i];
solve(l, mid);
solve(mid + 1, r);
}
int main() {
rd(n);
U (i, 1, n) a[i] = i;
solve(1, n);
report();
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
5 1 0 1
output:
0 1 1 1 5 5 0 1 1 1 2 2 0 4 4 4 3 3