QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373551#5200. BinCoinInfinityNS#RE 1ms4136kbC++143.2kb2024-04-01 20:10:182024-04-01 20:10:19

Judging History

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

  • [2024-04-01 20:10:19]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4136kb
  • [2024-04-01 20:10:18]
  • 提交

answer

#include<bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()

using namespace std;

const int N=1001;
vector<int> parent(N);
vector<pair<int,int>> pos(N);
vector<bool> ok(N);
void solve(vector<vector<int>> tr,int par){
    if(sz(tr[0])==1){
        parent[tr[0][0]]=par;
        return;
    }
    for(int i=0;i<sz(tr[0]);i++){
        pos[tr[0][i]]={-1,-1};
        ok[tr[0][i]]=1;
    }
    for(int i=0;i<sz(tr);i++){
        for(int j=0;j<sz(tr[i]);j++){
            int p=j;
            int val=tr[i][j];
            if(pos[val].f==-1||pos[val].f==p){
                pos[val].f=p;
            }
            else{
                if(pos[val].s==-1||pos[val].s==p){
                    pos[val].s=p;
                }
                else{
                    ok[val]=0;
                }
            }
        }
    }
    vector<int> cand;
    int roott=-1,poss=0;
    for(int i=0;i<sz(tr[0]);i++){
        int t=tr[0][i];
        //printf("%i: %i %i %i\n",t,ok[t]?1:0,pos[t].f,pos[t].s);
        if(ok[t]){
            if(roott==-1){
                roott=t;
            }
            else{
                if(pos[t].s==-1)pos[t].s=pos[t].f;
                if(min(pos[t].f,pos[t].s)>poss){
                    poss=min(pos[t].f,pos[t].s);
                    roott=t;
                }
            }
        }
    }
    cand.pb(roott);
    for(auto root:cand){
        //printf("%i!\n",root);
        vector<vector<int>> lv,rv;
        vector<int> nl,nr;
        bool ok=1;
        for(int j=0;j<sz(tr);j++){
            vector<int> pre,posle;
            bool nasao=0;
            for(int i=0;i<sz(tr[j]);i++){
                if(tr[j][i]==root){
                    nasao=1;
                    continue;
                }
                if(!nasao)pre.pb(tr[j][i]);
                else posle.pb(tr[j][i]);
            }
            pair<vector<int>,vector<int>> tt={pre,posle};
            sort(all(pre));
            sort(all(posle));
            if(pre>posle)swap(pre,posle),swap(tt.f,tt.s);
            lv.pb(tt.f);
            rv.pb(tt.s);
            /*printf("pre: ");
            for(int i=0;i<sz(pre);i++){
                printf("%i ",pre[i]);
            }
            printf("posle: ");
            for(int i=0;i<sz(posle);i++){
                printf("%i ",posle[i]);
            }
            printf("\n");*/
            if(j==0){
                nl=pre;
                nr=posle;
            }
            else{
                if(nl!=pre||nr!=posle){
                    ok=0;
                    break;
                }
            }
        }
        //printf("%i\n",ok?1:0);
        if(ok){
            parent[root]=par;
            solve(lv,root);
            solve(rv,root);
            break;
        }
        assert(0);
    }
}
int main(){
    int n,k;
    scanf("%i %i",&n,&k);
    vector<vector<int>> vals(k,vector<int>(n));
    for(int i=0;i<k;i++){
        for(int j=0;j<n;j++){
            scanf("%i",&vals[i][j]);
        }
    }
    solve(vals,-1);
    for(int i=1;i<=n;i++){
        printf("%i ",parent[i]);
    }
    printf("\n");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4088kb

input:

3 50
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
1 2 3
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
1 2 3
1 2 3
3 2 1
1 2 3
3 2 1
3 2 1
3 2 1
1 2 3
1 2 3
3 2 1
3...

output:

2 -1 2 

result:

ok everything is fine

Test #2:

score: 0
Accepted
time: 1ms
memory: 3864kb

input:

5 60
2 4 3 5 1
1 5 2 4 3
1 5 2 4 3
1 5 2 4 3
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
1 5 3 4 2
3 4 2 5 1
2 4 3 5 1
1 5 2 4 3
3 4 2 5 1
2 4 3 5 1
2 4 3 5 1
1 5 2 4 3
3 4 2 5 1
3 4 2 5 1
1 5 2 4 3
2 4 3 5 1
1 5 2 4 3
1 5 3 4 2
3 4 2 5 1
1 5 3 4 2
1 5 2 4 3
1 5 3 4 2
1 5 2 4 3
2 4 3 5 1
2 4 3 5 1
2 4 3...

output:

5 4 4 5 -1 

result:

ok everything is fine

Test #3:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

11 73
11 1 7 8 5 6 10 3 9 4 2
5 6 10 8 7 1 11 3 9 4 2
9 3 11 1 7 8 5 6 10 4 2
2 4 11 1 7 8 5 6 10 3 9
9 3 7 1 11 8 10 6 5 4 2
2 4 10 6 5 8 7 1 11 3 9
9 3 7 1 11 8 5 6 10 4 2
11 1 7 8 10 6 5 3 9 4 2
9 3 10 6 5 8 7 1 11 4 2
2 4 5 6 10 8 11 1 7 3 9
2 4 11 1 7 8 10 6 5 3 9
2 4 10 6 5 8 11 1 7 3 9
9 3 10...

output:

8 4 4 -1 6 8 1 3 3 6 1 

result:

ok everything is fine

Test #4:

score: 0
Accepted
time: 1ms
memory: 4136kb

input:

21 81
9 18 14 13 3 4 7 10 2 21 15 16 5 19 20 12 11 1 17 8 6
14 13 7 4 3 10 2 18 9 21 20 12 6 8 11 1 17 19 15 16 5
2 10 14 13 3 4 7 18 9 21 17 1 11 8 6 12 20 19 5 16 15
2 10 7 4 3 13 14 18 9 21 15 16 5 19 6 8 17 1 11 12 20
15 16 5 19 6 8 17 1 11 12 20 21 9 18 7 4 3 13 14 10 2
5 16 15 19 11 1 17 8 6 1...

output:

8 10 4 13 16 8 4 12 18 18 1 19 10 13 16 19 1 21 21 12 -1 

result:

ok everything is fine

Test #5:

score: -100
Runtime Error

input:

239 100
31 148 157 39 186 205 65 129 197 152 238 154 9 207 36 92 109 48 230 58 175 135 50 77 11 52 102 21 139 142 210 138 200 83 214 98 209 1 195 17 55 141 146 101 91 174 184 67 27 235 6 198 208 43 236 143 94 29 60 104 120 155 78 40 218 234 147 4 34 38 239 212 112 116 72 59 211 79 82 32 7 170 113 10...

output:


result: