QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741324#9432. PermutationforgotmyhandleWA 0ms3468kbC++142.1kb2024-11-13 14:06:052024-11-13 14:06:06

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 14:06:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3468kb
  • [2024-11-13 14:06:05]
  • 提交

answer

#include <iostream>
#include <random>
#include <vector>
using namespace std;
random_device rd;
mt19937 mtrand(rd());
int n;
int ans[1005];
int f[1005];
void ini(int x) { for (; x; --x) f[x] = x; }
int getf(int x) { return (f[x] == x ? x : (f[x] = getf(f[x]))); }
int bel[1005];
int ask(int k, int x, int y) {
    cout << "0 ";
    for (int i = 1; i <= k; i++) cout << x << " ";
    for (int i = 1; i <= n - k; i++) cout << y << " ";
    cout << endl;
    cin >> k;
    return k;
}
void Solve(int l, int r, vector<int> S) {
    // cout << l << " " << r << "\n";
    // for (int i : S) cout << i << " ";
    // cout << endl;
    if (l == r) {
        ans[S[0]] = l;
        return;
    }
    int mid = (l + r) >> 1;
    ini(n);
    vector<int> v[2], tmp = S;
    int c0 = 0, c1 = 0;
    while (S.size()) {
        int x, y;
        if ((int)S.size() == 1) {
            x = S[0];
            if (!c0 || !c1) 
                bel[x] = !!c0;
            else 
                bel[x] = !ask(mid, x, c0);
            break;
        }
        x = mtrand() % S.size(), y = mtrand() % ((int)S.size() - 1);
        y += (y >= x);
        int t = ask(mid, S[x], S[y]);
        if (t == 0) 
            bel[c1 = S[x]] = 1, bel[c0 = S[y]] = 0, S.erase(S.begin() + max(x, y)), S.erase(S.begin() + min(x, y));
        else if (t == 2) 
            bel[c0 = S[x]] = 0, bel[c1 = S[y]] = 1, S.erase(S.begin() + max(x, y)), S.erase(S.begin() + min(x, y));
        else {
            f[getf(S[x])] = S[y];
            S.erase(S.begin() + x);
        }
        // cout << "ASDf\n";
        // for (auto s : S) cout << s << " ";
        // cout << endl;
    }
    // for (auto x : tmp) cout << x << " " << getf(x) << " " << bel[getf(x)] << " x" << endl;
    for (auto x : tmp) v[bel[getf(x)]].emplace_back(x);
    Solve(l, mid, v[0]);
    Solve(mid + 1, r, v[1]);
}
int main() {
    vector<int> v;
    cin >> n;
    for (int i = 1; i <= n; i++) v.emplace_back(i);
    Solve(1, n, v);
    cout << "1 ";
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3468kb

input:

5
0
0
1
1
2
2
0

output:

0 1 1 1 2 2 
0 5 5 5 3 3 
0 4 4 4 3 3 
0 3 3 4 4 4 
0 4 4 2 2 2 
0 3 4 4 4 4 
0 5 5 5 5 1 
1 4 3 1 2 5 

result:

wrong answer Wrong Anser