Submission #1032745

# Submission time Handle Problem Language Result Execution time Memory
1032745 2024-07-24T07:47:20 Z boyliguanhan Amusement Park (JOI17_amusement_park) C++17
73 / 100
20 ms 16092 KB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
namespace joi{
    vector<int>adj[100100],adj2[100100];
    bitset<100100>vis,inthisblok,deepest_path;
    int col[100100],CCcol,depdep=0,depnod,par[100100];
    void dfstree(int n){
        vis[n]=1;
        for(auto i:adj[n]){
            if(!vis[i]) {
                dfstree(i);
                adj2[i].push_back(n);
                adj2[n].push_back(i);
            }
        }
    }
    void getdeepest(int n,int dep){
        if(dep>depdep)
        depdep=dep,depnod=n;
        for(auto i:adj2[n])
            if(!col[i]&&i-par[n])
                getdeepest(i,dep+1);
    }
    void gowild(int n,int&CC,int color){
        if(!CC)return;
        if(!col[n])CC--,col[n]=color;
        for(auto i:adj2[n])
            if(i-par[n]&&(!col[i]||col[i]==color))
                gowild(i,CC,color);
    }
    void assigncols(int rt,int thecol){
        depdep=0;
        int CC=60;
        getdeepest(rt,1);
        int C=depnod;
        while(C-rt) deepest_path[C]=1,
            CC--,col[C]=thecol,C=par[C];
        gowild(rt,CC,thecol);
    }
    void preproc(int n,int p){
        par[n]=p;
        for(auto i:adj2[n])
            if(i-p)preproc(i,n);
    }
    int dfscol(int n){
        int sz=1;
        for(auto i:adj2[n])
            if(i-par[n])
                sz+=dfscol(i);
        if(sz>=60)
            assigncols(n,++CCcol),sz=0;
        return sz;
    }
}
vector<int>positions[10100];
void Joi(int N, int M, int A[], int B[], long long X, int T) {
    for(int i=0;i<M;i++)
        joi::adj[A[i]+1].push_back(B[i]+1),
        joi::adj[B[i]+1].push_back(A[i]+1);
    joi::dfstree(1);
    joi::preproc(1,0);
    joi::dfscol(1);
    for(int i=1;i<=N;i++) if(joi::col[i])
        positions[joi::col[i]].push_back(i);
    for(int i=1;i<=joi::CCcol;i++){
        long long X2=X;
        for(auto j:positions[i])
            MessageBoard(j-1,X2&1),X2>>=1;
    }
    for(int i=1;i<=N;i++) if(!joi::col[i])
        MessageBoard(i-1,0);
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
bitset<100100>messg;
void gooo(int nod){
    messg[nod]=Move(nod-1);
}
vector<int>path;
namespace ioi{
    vector<int>adj[100100],adj2[100100];
    bitset<100100>vis;
    int col[100100],CCcol,depdep=0,depnod,par[100100],deepest_path[100100];
    void dfstree(int n){
        vis[n]=1;
        for(auto i:adj[n]){
            if(!vis[i]) {
                dfstree(i);
                adj2[i].push_back(n);
                adj2[n].push_back(i);
            }
        }
        adj[n].clear();
    }
    void getdeepest(int n,int dep){
        if(dep>depdep)
            depdep=dep,depnod=n;
        for(auto i:adj2[n])
            if(!col[i]&&i-par[n])
                getdeepest(i,dep+1);
    }
    void gowild(int n,int&CC,int color){
        if(!CC)return;
        if(!col[n])CC--,col[n]=color;
        for(auto i:adj2[n])
            if(i-par[n]&&(!col[i]||col[i]==color))
                gowild(i,CC,color);
    }
    void assigncols(int rt,int thecol){
        depdep=0;
        int CC=60;
        getdeepest(rt,1);
        deepest_path[rt]=1;
        int C=depnod;
        while(C-rt) deepest_path[C]=1,
            CC--,col[C]=thecol,C=par[C];
        gowild(rt,CC,thecol);
    }
    void preproc(int n,int p){
        par[n]=p;
        for(auto i:adj2[n])
            if(i-p)preproc(i,n);
    }
    void makenocol(int n){
        col[n]=-1;
        for(auto i:adj2[n])
            if(i-par[n]&&!col[i])
                makenocol(i);
    }
    int dfscol(int n){
        int sz=1;
        for(auto i:adj2[n])
            if(i-par[n])
                sz+=dfscol(i);
        if(sz>=60)
            assigncols(n,++CCcol),sz=0;
        if(n==1&&sz){
            makenocol(n);
        }
        return sz;
    }
    void tofindall(int n){
        for(auto i:adj2[n])
            if(col[i]==col[n]&&!deepest_path[i]&&i!=par[n])
                gooo(i),tofindall(i);
        if(!deepest_path[n])
            gooo(par[n]);
        else for(auto i:adj2[n])
            if(i-par[n]&&deepest_path[i]&&col[i]==col[n])
                gooo(i),tofindall(i);
    }
    pair<int,int>getclos(int n){
        if(col[n]>0)return{0,n};
        pair<int,int>ans={1e9,1e9};
        for(auto i:adj2[n])
            if(i!=par[n])
                ans=min(ans,getclos(i));
        return {ans.first+1,ans.second};
    }
}
 
long long Ioi2(int P,int N){
    auto[x,y]=ioi::getclos(P);
    vector<int>path;
    if(y==1e9)return 9;
    do{
        path.push_back(y);
        y=ioi::par[y];
    }while(y-P);
    reverse(path.begin(),path.end());
    for(auto i:path)
        gooo(P=i);
    ioi::tofindall(P);
    vector<int>important;
    for(int i=1;i<=N;i++)
        if(ioi::col[i]==ioi::col[P])
            important.push_back(i);
    long long ans=0;
    reverse(important.begin(),important.end());
    for(auto i:important)
        ans=ans<<1|messg[i];
    return ans;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    for(int i=0;i<M;i++)
        ioi::adj[A[i]+1].push_back(B[i]+1),
        ioi::adj[B[i]+1].push_back(A[i]+1);
    P++;
    messg[P]=V;
    ioi::dfstree(1);
    ioi::preproc(1,0);
    ioi::dfscol(1);
    if(ioi::col[P]==-1){
        return Ioi2(P,N);
    }
    while(!ioi::col[P])
        gooo(P=ioi::par[P]);
    while(ioi::col[ioi::par[P]]==ioi::col[P])
        gooo(P=ioi::par[P]);
    ioi::tofindall(P);
    vector<int>important;
    for(int i=1;i<=N;i++)
        if(ioi::col[i]==ioi::col[P])
            important.push_back(i);
    long long ans=0;
    reverse(important.begin(),important.end());
    for(auto i:important)
        ans=(ans<<1)|messg[i];
    return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 12044 KB Output is correct
2 Correct 3 ms 12048 KB Output is correct
3 Correct 4 ms 12316 KB Output is correct
4 Correct 4 ms 12048 KB Output is correct
5 Correct 3 ms 12060 KB Output is correct
6 Correct 3 ms 12048 KB Output is correct
7 Correct 4 ms 12304 KB Output is correct
8 Correct 3 ms 12312 KB Output is correct
9 Correct 3 ms 12320 KB Output is correct
10 Correct 3 ms 12060 KB Output is correct
11 Correct 5 ms 12608 KB Output is correct
12 Correct 3 ms 12060 KB Output is correct
13 Correct 4 ms 12320 KB Output is correct
14 Correct 3 ms 12320 KB Output is correct
15 Correct 4 ms 12320 KB Output is correct
16 Correct 4 ms 12064 KB Output is correct
17 Correct 3 ms 12320 KB Output is correct
18 Correct 3 ms 12316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15940 KB Output is correct
2 Correct 19 ms 15972 KB Output is correct
3 Correct 19 ms 15944 KB Output is correct
4 Correct 14 ms 14556 KB Output is correct
5 Correct 13 ms 15076 KB Output is correct
6 Correct 13 ms 15068 KB Output is correct
7 Correct 16 ms 15060 KB Output is correct
8 Correct 14 ms 15064 KB Output is correct
9 Correct 14 ms 15064 KB Output is correct
10 Correct 11 ms 14564 KB Output is correct
11 Correct 11 ms 14564 KB Output is correct
12 Correct 13 ms 14024 KB Output is correct
13 Correct 12 ms 14036 KB Output is correct
14 Correct 11 ms 14040 KB Output is correct
15 Correct 12 ms 14300 KB Output is correct
16 Correct 11 ms 14296 KB Output is correct
17 Correct 16 ms 14556 KB Output is correct
18 Correct 13 ms 14552 KB Output is correct
19 Correct 13 ms 14548 KB Output is correct
20 Correct 11 ms 15156 KB Output is correct
21 Correct 11 ms 15072 KB Output is correct
22 Incorrect 13 ms 14680 KB Wrong Answer [7]
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12048 KB Output is correct
2 Correct 3 ms 12060 KB Output is correct
3 Correct 3 ms 12056 KB Output is correct
4 Correct 3 ms 12848 KB Output is correct
5 Correct 4 ms 12856 KB Output is correct
6 Correct 4 ms 12856 KB Output is correct
7 Correct 4 ms 13016 KB Output is correct
8 Correct 4 ms 12860 KB Output is correct
9 Correct 14 ms 15832 KB Output is correct
10 Correct 11 ms 15832 KB Output is correct
11 Correct 11 ms 16092 KB Output is correct
12 Correct 2 ms 12044 KB Output is correct
13 Correct 3 ms 12044 KB Output is correct
14 Correct 3 ms 12044 KB Output is correct
15 Correct 3 ms 12048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15980 KB Output is correct
2 Correct 19 ms 15936 KB Output is correct
3 Correct 19 ms 15972 KB Output is correct
4 Correct 13 ms 14552 KB Output is correct
5 Correct 15 ms 15580 KB Output is correct
6 Correct 13 ms 15072 KB Output is correct
7 Correct 15 ms 15068 KB Output is correct
8 Correct 13 ms 14552 KB Output is correct
9 Correct 13 ms 14816 KB Output is correct
10 Correct 13 ms 14560 KB Output is correct
11 Correct 11 ms 14560 KB Output is correct
12 Correct 12 ms 14024 KB Output is correct
13 Correct 11 ms 14032 KB Output is correct
14 Correct 12 ms 14288 KB Output is correct
15 Correct 12 ms 14296 KB Output is correct
16 Correct 13 ms 14300 KB Output is correct
17 Correct 17 ms 14420 KB Output is correct
18 Correct 13 ms 14560 KB Output is correct
19 Correct 16 ms 14548 KB Output is correct
20 Correct 11 ms 15076 KB Output is correct
21 Correct 10 ms 15092 KB Output is correct
22 Correct 13 ms 15068 KB Output is correct
23 Correct 17 ms 15004 KB Output is correct
24 Correct 13 ms 15060 KB Output is correct
25 Correct 13 ms 15064 KB Output is correct
26 Correct 13 ms 15068 KB Output is correct
27 Correct 18 ms 15040 KB Output is correct
28 Correct 13 ms 14812 KB Output is correct
29 Correct 11 ms 14544 KB Output is correct
30 Correct 13 ms 15056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 15964 KB Output is correct
2 Correct 19 ms 15952 KB Output is correct
3 Correct 20 ms 15792 KB Output is correct
4 Correct 14 ms 14560 KB Output is correct
5 Correct 16 ms 15592 KB Output is correct
6 Correct 15 ms 15060 KB Output is correct
7 Correct 14 ms 14556 KB Output is correct
8 Correct 14 ms 15068 KB Output is correct
9 Correct 14 ms 15076 KB Output is correct
10 Correct 12 ms 14560 KB Output is correct
11 Correct 12 ms 14560 KB Output is correct
12 Correct 13 ms 14248 KB Output is correct
13 Correct 12 ms 14036 KB Output is correct
14 Correct 11 ms 14292 KB Output is correct
15 Correct 13 ms 14292 KB Output is correct
16 Correct 12 ms 14292 KB Output is correct
17 Correct 13 ms 14556 KB Output is correct
18 Correct 13 ms 14552 KB Output is correct
19 Correct 13 ms 14420 KB Output is correct
20 Correct 11 ms 15068 KB Output is correct
21 Correct 11 ms 15072 KB Output is correct
22 Correct 18 ms 15052 KB Output is correct
23 Correct 13 ms 15068 KB Output is correct
24 Correct 14 ms 15068 KB Output is correct
25 Correct 13 ms 15064 KB Output is correct
26 Correct 15 ms 14612 KB Output is correct
27 Correct 14 ms 15056 KB Output is correct
28 Correct 13 ms 15068 KB Output is correct
29 Correct 13 ms 15056 KB Output is correct
30 Correct 14 ms 15064 KB Output is correct
31 Correct 3 ms 12060 KB Output is correct
32 Correct 3 ms 12056 KB Output is correct
33 Correct 3 ms 12312 KB Output is correct
34 Correct 2 ms 12048 KB Output is correct
35 Correct 3 ms 12048 KB Output is correct
36 Correct 2 ms 12056 KB Output is correct
37 Correct 3 ms 12060 KB Output is correct
38 Correct 3 ms 12048 KB Output is correct
39 Correct 3 ms 12060 KB Output is correct
40 Correct 3 ms 12060 KB Output is correct
41 Incorrect 3 ms 12060 KB Wrong Answer [7]
42 Halted 0 ms 0 KB -