QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#780063 | #9432. Permutation | kfgzsdd | WA | 290ms | 3888kb | C++23 | 2.3kb | 2024-11-25 00:27:54 | 2024-11-25 00:27:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937 rnd(time(0));
int n, res, ans[10005], f[10005], qy[10005], re[10005];
int find(int x) {
if (x == f[x]) {
return x;
}
return f[x] = find(f[x]);
}
void print() {
cout << "1 ";
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
return ;
}
void ask() {
cout << "0 ";
for (int i = 1; i <= n; i++) {
cout << qy[i] << " ";
}
cout << "\n";
cout.flush();
}
void solve(int l, int r, vector<int> cur) {
if (l == r) {
ans[l] = cur[0];
return ;
}
int mid = l + r >> 1;
for (int i = 0; i < cur.size(); i++) {
f[cur[i]] = cur[i];
}
vector<int> l1, r1, del;
while (cur.size() > 1) {
random_shuffle(cur.begin(), cur.end());
int u = cur[cur.size() - 1];
int v = cur[cur.size() - 2];
cur.pop_back();
cur.pop_back();
for (int j = 1; j <= mid; j++) {
qy[j] = u;
}
for (int j = mid + 1; j <= n; j++) {
qy[j] = v;
}
ask();
cin >> res;
if (!res) {
l1.push_back(v);
r1.push_back(u);
re[v] = 0;
re[u] = 1;
}
if (res == 1) {
del.push_back(u);
cur.push_back(v);
f[u] = v;
}
if (res == 2) {
l1.push_back(u);
r1.push_back(v);
re[u] = 0;
re[v] = 1;
}
}
if (cur.size() == 1) {
int lft = cur[0];
if (l1.size()) {
for (int i = 1; i <= mid; i++) {
qy[i] = lft;
}
for (int i = mid + 1; i <= n; i++) {
qy[i] = l1[0];
}
ask();
cin >> res;
if (!res) {
r1.push_back(lft);
re[lft] = 1;
} else {
l1.push_back(lft);
re[lft] = 0;
}
} else if (r1.size()) {
for (int i = 1; i <= mid; i++) {
qy[i] = r1[0];
}
for (int i = mid + 1; i <= n; i++) {
qy[i] = lft;
}
ask();
cin >> res;
if (!res) {
l1.push_back(lft);
re[lft] = 0;
} else {
r1.push_back(lft);
re[lft] = 1;
}
}
}
for (int i = 0; i < del.size(); i++) {
int fa = find(del[i]);
if (!re[fa]) {
l1.push_back(del[i]);
} else {
r1.push_back(del[i]);
}
}
solve(l, mid, l1);
solve(mid + 1, r, r1);
}
signed main() {
cin >> n;
if (n == 1) {
print();
} else {
vector<int> cur;
for (int i = 1; i <= n; i++) {
cur.push_back(i);
}
solve(1, n, cur);
print();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
input:
5 0 1 0 0 1 0 2
output:
0 1 1 1 3 3 0 4 4 4 2 2 0 5 5 5 2 2 0 2 2 3 3 3 0 4 4 3 3 3 0 4 3 3 3 3 0 1 1 1 1 5 1 3 4 2 1 5
result:
ok Accepted
Test #2:
score: 0
Accepted
time: 290ms
memory: 3816kb
input:
1000 1 1 1 1 0 1 1 2 1 1 0 0 1 0 1 2 1 0 1 1 1 2 1 0 1 1 1 1 0 2 0 1 1 0 2 1 1 1 1 2 0 2 1 2 1 2 0 0 0 1 1 1 2 1 0 1 2 2 0 2 1 1 1 1 1 0 2 1 1 0 2 1 2 0 1 1 0 2 1 1 0 1 1 1 2 1 1 0 1 1 1 0 0 2 1 1 1 1 1 0 1 1 2 0 1 1 2 0 1 2 2 1 2 0 2 1 1 1 1 1 1 0 2 1 0 1 2 1 1 1 1 0 0 0 2 0 1 2 2 1 2 0 2 0 1 1 0 2...
output:
0 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 951 95...
result:
ok Accepted
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3888kb
input:
1
output:
1 0
result:
wrong answer Integer element [index=1] equals to 0, violates the range [1, 1]