답안 #967647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967647 2024-04-22T14:50:12 Z happy_node Amusement Park (JOI17_amusement_park) C++17
83 / 100
20 ms 4536 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const int MX=10005;
 
vector<int> adj[MX];
 
int timer=-1;
vector<int> euler;
int sz[MX], par[MX], tin[MX], tout[MX];


struct DSU {
        int par[MX];
 
        int find(int v) {
                return par[v]==v?v:par[v]=find(par[v]);
        }
 
        bool merge(int u, int v) {
                u=find(u),v=find(v);
                if(u==v) return false;
                par[u]=v;
                return true;
        }
 
        void prep(int N) {
                for(int i=0;i<N;i++) par[i]=i;
        }
} DS;
 
void dfs(int v, int p) {
        tin[v]=++timer;
        euler.push_back(v);
        sz[v]=1;
        par[v]=p;
        for(auto u:adj[v]) {
                if(u==p) continue;
                dfs(u,v);
                sz[v]+=sz[u];
        }
        tout[v]=timer;
}
 
void Joi(int N, int M, int A[], int B[], long long X, int T) {
        DS.prep(N);
        
        for(int i=0;i<M;i++) {
                int x=A[i],y=B[i];
                if(DS.merge(x,y)) {
                        adj[x].push_back(y);
                        adj[y].push_back(x);
                }
        }

        dfs(0,-1);
        for(int i=0;i<N;i++) {
                sort(adj[i].begin(),adj[i].end(),[&](int i, int j) {
                        return sz[i]<sz[j];
                });     
        }
        euler.clear();
        timer=-1;
        dfs(0,-1);
 
        for(int i=0;i<N;i++) {
                int k=i%60;
                MessageBoard(euler[i],X>>k&1);
        }
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const int MX=10005;
 
vector<int> adj[MX];
 
int timer=-1;
vector<int> euler;
int sz[MX], par[MX], tin[MX], tout[MX];
 
void dfs(int v, int p) {
        tin[v]=++timer;
        euler.push_back(v);
        sz[v]=1;
        par[v]=p;
        for(auto u:adj[v]) {
                if(u==p) continue;
                dfs(u,v);
                sz[v]+=sz[u];
        }
        tout[v]=timer;
}
 
ll get(int x, int y) {
        return y*(1LL<<(tin[x]%60));
}
 
ll res=0, cnt=0;
 
bool vis[60];
 
void dfs0(int v, int p) {
        if(cnt==60) return;
        for(auto u:adj[v]) {
                if(u==p) continue;
                if(!vis[tin[u]%60]) cnt++;
                vis[tin[u]%60]=1;
                res|=get(u,Move(u));
                dfs0(u,v);
                if(cnt==60) return;
                Move(v);
        }
}

struct DSU {
        int par[MX];
 
        int find(int v) {
                return par[v]==v?v:par[v]=find(par[v]);
        }
 
        bool merge(int u, int v) {
                u=find(u),v=find(v);
                if(u==v) return false;
                par[u]=v;
                return true;
        }
 
        void prep(int N) {
                for(int i=0;i<N;i++) par[i]=i;
        }
} ds;
 
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
        ds.prep(N);
        
        for(int i=0;i<M;i++) {
                int x=A[i],y=B[i];
                if(ds.merge(x,y)) {
                        adj[x].push_back(y);
                        adj[y].push_back(x);
                }
        }

        dfs(0,-1);
        for(int i=0;i<N;i++) {
                sort(adj[i].begin(),adj[i].end(),[&](int i, int j) {
                        return sz[i]<sz[j];
                });     
        }
        euler.clear();
        timer=-1;
        dfs(0,-1);

        int k=V;
        while(sz[P]<60) {
                P=par[P];
                k=Move(P);
        }
 
        res|=get(P,k);
        cnt++;
        vis[tin[P]%60]=1;
        dfs0(P,par[P]);
 
        return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1308 KB Output is correct
2 Correct 2 ms 1292 KB Output is correct
3 Correct 2 ms 1312 KB Output is correct
4 Correct 1 ms 1308 KB Output is correct
5 Correct 1 ms 1308 KB Output is correct
6 Correct 2 ms 1296 KB Output is correct
7 Correct 1 ms 1312 KB Output is correct
8 Correct 1 ms 1312 KB Output is correct
9 Correct 2 ms 1304 KB Output is correct
10 Correct 1 ms 1292 KB Output is correct
11 Correct 3 ms 1348 KB Output is correct
12 Correct 1 ms 1296 KB Output is correct
13 Correct 1 ms 1304 KB Output is correct
14 Correct 1 ms 1308 KB Output is correct
15 Correct 1 ms 1304 KB Output is correct
16 Correct 2 ms 1300 KB Output is correct
17 Correct 2 ms 1308 KB Output is correct
18 Correct 1 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3916 KB Output is correct
2 Correct 19 ms 3940 KB Output is correct
3 Correct 17 ms 3936 KB Output is correct
4 Correct 11 ms 3552 KB Output is correct
5 Correct 12 ms 3956 KB Output is correct
6 Correct 11 ms 3552 KB Output is correct
7 Correct 11 ms 3800 KB Output is correct
8 Correct 11 ms 3800 KB Output is correct
9 Correct 11 ms 3804 KB Output is correct
10 Correct 9 ms 3292 KB Output is correct
11 Correct 9 ms 3288 KB Output is correct
12 Correct 10 ms 3276 KB Output is correct
13 Correct 10 ms 3768 KB Output is correct
14 Correct 10 ms 3288 KB Output is correct
15 Correct 11 ms 3300 KB Output is correct
16 Correct 10 ms 3288 KB Output is correct
17 Correct 11 ms 3436 KB Output is correct
18 Correct 14 ms 3460 KB Output is correct
19 Correct 11 ms 3292 KB Output is correct
20 Correct 9 ms 3804 KB Output is correct
21 Correct 8 ms 3804 KB Output is correct
22 Correct 10 ms 3544 KB Output is correct
23 Correct 11 ms 3812 KB Output is correct
24 Correct 11 ms 3552 KB Output is correct
25 Correct 11 ms 3800 KB Output is correct
26 Correct 11 ms 3808 KB Output is correct
27 Correct 11 ms 3800 KB Output is correct
28 Correct 11 ms 3800 KB Output is correct
29 Correct 10 ms 3532 KB Output is correct
30 Correct 10 ms 3544 KB Output is correct
31 Correct 1 ms 1308 KB Output is correct
32 Correct 1 ms 1308 KB Output is correct
33 Correct 1 ms 1304 KB Output is correct
34 Correct 1 ms 1796 KB Output is correct
35 Correct 2 ms 1292 KB Output is correct
36 Correct 1 ms 1808 KB Output is correct
37 Correct 0 ms 1308 KB Output is correct
38 Correct 0 ms 1292 KB Output is correct
39 Correct 1 ms 1304 KB Output is correct
40 Correct 1 ms 1548 KB Output is correct
41 Correct 0 ms 1304 KB Output is correct
42 Correct 1 ms 1296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1296 KB Output is correct
2 Correct 1 ms 1296 KB Output is correct
3 Correct 0 ms 1308 KB Output is correct
4 Correct 2 ms 1848 KB Output is correct
5 Correct 2 ms 1848 KB Output is correct
6 Correct 2 ms 1840 KB Output is correct
7 Correct 3 ms 1840 KB Output is correct
8 Correct 2 ms 1848 KB Output is correct
9 Correct 9 ms 4316 KB Output is correct
10 Correct 9 ms 4316 KB Output is correct
11 Correct 9 ms 4324 KB Output is correct
12 Correct 1 ms 1296 KB Output is correct
13 Correct 1 ms 1296 KB Output is correct
14 Correct 1 ms 1308 KB Output is correct
15 Correct 1 ms 1308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3948 KB Output is correct
2 Correct 17 ms 3944 KB Output is correct
3 Correct 17 ms 3940 KB Output is correct
4 Correct 11 ms 3208 KB Output is correct
5 Correct 12 ms 4320 KB Output is correct
6 Correct 11 ms 3808 KB Output is correct
7 Correct 11 ms 4188 KB Output is correct
8 Correct 11 ms 3808 KB Output is correct
9 Correct 11 ms 3544 KB Output is correct
10 Correct 10 ms 3296 KB Output is correct
11 Correct 10 ms 3288 KB Output is correct
12 Correct 10 ms 3272 KB Output is correct
13 Correct 12 ms 3276 KB Output is correct
14 Correct 11 ms 3276 KB Output is correct
15 Correct 11 ms 3296 KB Output is correct
16 Correct 11 ms 3296 KB Output is correct
17 Correct 11 ms 3212 KB Output is correct
18 Correct 11 ms 3164 KB Output is correct
19 Correct 11 ms 3288 KB Output is correct
20 Correct 8 ms 3808 KB Output is correct
21 Correct 9 ms 3804 KB Output is correct
22 Correct 11 ms 3800 KB Output is correct
23 Correct 11 ms 3684 KB Output is correct
24 Correct 11 ms 3808 KB Output is correct
25 Correct 11 ms 3800 KB Output is correct
26 Correct 11 ms 3800 KB Output is correct
27 Correct 11 ms 3800 KB Output is correct
28 Correct 11 ms 3548 KB Output is correct
29 Correct 11 ms 3524 KB Output is correct
30 Correct 11 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3936 KB Output is correct
2 Correct 17 ms 3936 KB Output is correct
3 Correct 18 ms 3944 KB Output is correct
4 Correct 11 ms 3384 KB Output is correct
5 Correct 11 ms 4536 KB Output is correct
6 Correct 11 ms 3896 KB Output is correct
7 Correct 13 ms 4360 KB Output is correct
8 Correct 11 ms 3896 KB Output is correct
9 Correct 11 ms 3888 KB Output is correct
10 Correct 10 ms 3396 KB Output is correct
11 Correct 10 ms 3388 KB Output is correct
12 Correct 10 ms 3368 KB Output is correct
13 Correct 9 ms 3360 KB Output is correct
14 Correct 10 ms 3372 KB Output is correct
15 Correct 11 ms 3388 KB Output is correct
16 Correct 15 ms 3636 KB Output is correct
17 Correct 11 ms 3384 KB Output is correct
18 Correct 11 ms 3384 KB Output is correct
19 Correct 11 ms 3392 KB Output is correct
20 Correct 8 ms 3900 KB Output is correct
21 Correct 9 ms 3904 KB Output is correct
22 Correct 11 ms 3900 KB Output is correct
23 Correct 12 ms 3924 KB Output is correct
24 Correct 11 ms 3912 KB Output is correct
25 Correct 11 ms 3900 KB Output is correct
26 Correct 10 ms 3904 KB Output is correct
27 Correct 11 ms 3900 KB Output is correct
28 Correct 11 ms 3992 KB Output is correct
29 Correct 10 ms 3880 KB Output is correct
30 Correct 10 ms 3844 KB Output is correct
31 Correct 1 ms 1312 KB Output is correct
32 Correct 1 ms 1548 KB Output is correct
33 Correct 1 ms 1308 KB Output is correct
34 Incorrect 1 ms 1300 KB Output isn't correct
35 Halted 0 ms 0 KB -