QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741844#9432. PermutationremmymilkywayRE 0ms0kbC++231.9kb2024-11-13 15:20:342024-11-13 15:20:39

Judging History

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

  • [2024-11-13 15:20:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-13 15:20:34]
  • 提交

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 - 1; i++) {
            pos0.push_back(val[i]);
        }
    } else {
        for (int i = lst; i <= idx - 1; 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5
1
2
0
2

output:

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

result: