QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#652095#9432. PermutationUESTC_Snow_Halation#WA 243ms3696kbC++146.2kb2024-10-18 18:19:492024-10-18 18:19:50

Judging History

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

  • [2024-10-18 18:19:50]
  • 评测
  • 测评结果:WA
  • 用时:243ms
  • 内存:3696kb
  • [2024-10-18 18:19:49]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define FOR() int le=e[u].size();for(int i=0;i<le;i++)
#define QWQ cout<<"QwQ\n";
#define ll long long
#include <vector>
#include <queue>
#include <map>
#define poly vector<int>

using namespace std;
const int N=5010;
const int qwq=303030;
const int inf=0x3f3f3f3f;

inline int read() {
    int sum = 0, ff = 1; char c = getchar();
    while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
    while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
    return sum * ff;
}

int n;
poly zong,ling;
int id[N];
int ans[N];
int tim;
int a[N];
int yi1[N],yi2[N],cnt;

int ask() {
    tim++;
    if(tim>6660) { while(tim++) { tim--; } }
    cout<<"0 ";
    for(int i=1;i<=n;i++) cout<<a[i]<<" \n"[i==n];
    fflush(stdout);
    return read();
}

void outing() {
    cout<<"1 ";
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
    fflush(stdout);
}

inline void fuzhi(int cl) { for(int i=1;i<=n;i++) a[i] = cl; }

void solve(int l,int r,poly now,int cl) {
    // cout<<"l = "<<l<<" r = "<<r<<" cl = "<<cl<<" : ";
    // for(int v : now) cout<<v<<" ";
    // cout<<endl;
    if(l==r) { ans[ id[l] ] = now[0]; return ; }
    if(r-l==1) {
        fuzhi(cl); a[ id[l] ] = now[0];
        int wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[0];
            ans[ id[l+1] ] = now[1];
        }
        else {
            ans[ id[l] ] = now[1];
            ans[ id[l+1] ] = now[0];
        }
        return ;
    }
    poly xia = ling;
    if(r-l==2 && cl) {
        fuzhi(cl); a[ id[l] ] = now[0];
        int wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[0];
            xia.push_back(now[1]);
            xia.push_back(now[2]);
            solve(l+1,r,xia,cl);
            return ;
        }
        a[ id[l] ] = now[1];
        wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[1];
            xia.push_back(now[0]);
            xia.push_back(now[2]);
            solve(l+1,r,xia,cl);
            return ;
        }
        ans[ id[l] ] = now[2];
        xia.push_back(now[0]);
        xia.push_back(now[1]);
        solve(l+1,r,xia,cl);
        return ;
    }
    if(r-l==3 && cl) {
        fuzhi(cl); a[ id[l] ] = now[0];
        int wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[0];
            xia.push_back(now[1]);
            xia.push_back(now[2]);
            xia.push_back(now[3]);
            solve(l+1,r,xia,cl);
            return ;
        }
        a[ id[l] ] = now[1];
        wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[1];
            xia.push_back(now[0]);
            xia.push_back(now[2]);
            xia.push_back(now[3]);
            solve(l+1,r,xia,cl);
            return ;
        }
        a[ id[l] ] = now[2];
        wo = ask()-1;
        if(wo) {
            ans[ id[l] ] = now[2];
            xia.push_back(now[0]);
            xia.push_back(now[1]);
            xia.push_back(now[3]);
            solve(l+1,r,xia,cl);
            return ;
        }
        ans[ id[l] ] = now[3];
        xia.push_back(now[0]);
        xia.push_back(now[1]);
        xia.push_back(now[2]);
        solve(l+1,r,xia,cl);
        return ;
    }

    cnt = 0;
    poly L = ling;
    poly R = ling;

    int mid = l+r >> 1;
    for(int i=0;i+1<now.size();i+=2) {
        int u = now[i], v = now[i+1];
        fuzhi(cl);
        for(int j=l;j<=mid;j++) a[ id[j] ] = u;
        for(int j=mid+1;j<=r;j++) a[ id[j] ] = v;
        int wo = ask(); if(cl) wo--;
        if(wo==1) {
            yi1[++cnt] = u;
            yi2[cnt] = v;
        }
        else if(wo==0) {
            L.push_back(v);
            R.push_back(u);
        }
        else {
            L.push_back(u);
            R.push_back(v);
        }
    }
    int tian = cl;
    if(!tian) tian = R[0];
    for(int i=1;i+1<=cnt;i+=2) {
        int A = yi1[i], B = yi2[i], C = yi1[i+1], D = yi2[i+1];
        fuzhi(cl);
        for(int j=l;j<=mid;j++) a[ id[j] ] = A;
        for(int j=mid+1;j<=r;j++) a[ id[j] ] = D;
        int wo = ask(); if(cl) wo--;
        if(wo==0) {
            R.push_back(A);
            R.push_back(B);
            L.push_back(C);
            L.push_back(D);
        }
        if(wo==2) {
            R.push_back(C);
            R.push_back(D);
            L.push_back(A);
            L.push_back(B);
        }
        if(wo==1) {
            for(int j=l;j<=mid;j++) a[ id[j] ] = tian;
            int wo = ask(); if(cl) wo--;
            if(wo) {
                R.push_back(A);
                R.push_back(B);
                R.push_back(C);
                R.push_back(D);
            }
            else {
                L.push_back(A);
                L.push_back(B);
                L.push_back(C);
                L.push_back(D);
            }
        }
    }

    if(cnt&1) {
        int i = cnt;
        fuzhi(tian);
        for(int j=mid+1;j<=r;j++) a[ id[j] ] = yi2[i];
        int wo = ask(); if(cl) wo--;
        if(wo) {
            R.push_back(yi1[i]);
            R.push_back(yi2[i]);
        }
        else {
            L.push_back(yi1[i]);
            L.push_back(yi2[i]);
        }
    }

    if(L.size()!=(mid-l+1)) L.push_back(now.back());
    if(R.size()!=(r-mid)) R.push_back(now.back());
    solve(l,mid,L,R[0]);
    solve(mid+1,r,R,L[0]);
}

int main() {
    srand(time(NULL));
    n = read();
    if(n<=70) {
        int yi = 0;
        for(int i=1;i<=n;i++) {
            fuzhi(2); a[i] = 1;
            int wo = ask();
            if(wo==2) {yi = i; break;}
        }
        ans[yi] = 1;
        for(int i=1;i<=n;i++) {
            if(i==yi) continue;
            fuzhi(1);
            for(int j=2;j<=n;j++) {
                a[i] = j;
                int wo = ask();
                if(wo==2) {
                    ans[i] = j;
                    break;
                }
            }
        }
        outing();
        return 0;
    }

    for(int i=1;i<=n;i++) id[i] = i, zong.push_back(i);
    random_shuffle(id+1,id+n+1);
    solve(1,n,zong,0);
    outing();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

5
1
1
0
2
1
2
1
1
2
2
1
1
1
2

output:

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

result:

ok Accepted

Test #2:

score: 0
Accepted
time: 243ms
memory: 3640kb

input:

1000
2
0
1
1
1
1
1
1
1
0
1
0
1
2
2
2
2
1
0
2
1
2
1
1
1
0
0
0
1
2
1
2
2
2
0
1
2
0
2
1
1
1
1
2
1
0
1
1
0
0
0
0
1
2
2
1
2
1
2
1
1
0
1
1
1
1
1
1
1
0
2
1
1
1
1
1
2
2
1
2
0
1
1
0
2
1
1
0
1
0
2
1
1
1
1
1
0
2
1
1
1
1
0
0
1
0
1
2
1
1
1
0
0
1
1
1
0
2
1
1
1
0
1
2
0
1
1
2
1
2
2
1
1
1
1
1
1
0
1
0
0
1
2
1
1
1
0
1...

output:

0 1 1 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 1 1 2 1 2 2 2 2 1 2 2 2 2 1 1 1 2 2 1 2 2 1 2 1 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 1 1 1 2 1 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 2 2 1 1 2 1 2 2 2 2 1 1 2 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 2 1 1 1 2 2 2 ...

result:

ok Accepted

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3696kb

input:

1
1

output:

0 1
1 0 

result:

wrong answer Integer element [index=1] equals to 0, violates the range [1, 1]