QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#741832 | #9432. Permutation | remmymilkyway | RE | 1ms | 3804kb | C++23 | 1.9kb | 2024-11-13 15:19:06 | 2024-11-13 15:19:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, ans[maxn];
int ask(int mid, int x, int y) {
printf("0 ");
for (int i = 1; i <= mid; i++) {
printf("%d ", x);
}
for (int i = mid + 1; i <= n; i++) {
printf("%d ", y);
}
printf("\n");
fflush(stdout);
int res;
scanf("%d", &res);
return res;
}
void query(int l, int r, vector<int> val) {
if (l == r) {
ans[l] = val[0];
return;
}
int mid = (l + r) >> 1;
shuffle(val.begin(), val.end(), rng);
vector<int> pos0, pos1;
int idx = 0, lst = 0;
while (idx + 1 < (int)val.size()) {
int cur = ask(mid, val[idx], val[idx + 1]);
if (cur == 0) {
for (int i = lst; i <= idx; i++) {
pos1.push_back(val[i]);
}
pos0.push_back(val[idx + 1]);
idx += 2;
lst = idx;
} else if (cur == 2) {
for (int i = lst; i <= idx; i++) {
pos0.push_back(val[i]);
}
pos1.push_back(val[idx + 1]);
idx += 2;
lst = idx;
} else {
idx++;
}
}
if ((int)pos0.size() < mid - l + 1) {
for (int i = lst; i <= idx; i++) {
pos0.push_back(val[i]);
}
} else {
for (int i = lst; i <= idx; i++) {
pos1.push_back(val[i]);
}
}
query(l, mid, pos0);
query(mid + 1, r, pos1);
}
int main() {
scanf("%d", &n);
vector<int> cur;
for (int i = 1; i <= n; i++) {
cur.push_back(i);
}
query(1, n, cur);
printf("1 ");
for (int i = 1; i <= n; i++) {
printf("%d ", ans[i]);
}
printf("\n");
fflush(stdout);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3804kb
input:
5 0 0 0 2 0
output:
0 1 1 1 4 4 0 5 5 5 3 3 0 2 2 3 3 3 0 3 4 4 4 4 0 5 5 5 5 1 1 3 4 2 1 5
result:
ok Accepted
Test #2:
score: -100
Runtime Error
input:
1000 1 2 0 2 0 1 2 1 0 1 1 2 0 1 1 2 2 1 1 0 0 1 1 2 1 1 2 2 2 2 1 2 1 0 1 1 1 1 0 1 1 0 0 0 2 0 1 2 0 2 1 0 1 1 0 0 1 0 0 2 1 0 0 2 1 2 1 1 1 2 0 1 1 1 1 1 2 1 0 2 2 1 1 1 1 2 1 2 2 0 0 0 2 0 0 1 0 1 1 1 0 2 2 2 2 1 2 1 0 1 1 1 1 0 0 1 1 1 1 2 0 1 2 2 2 0 0 2 2 0 1 1 1 0 2 2 1 2 2 1 1 1 1 1 1 1 1 1...
output:
0 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 243 24...