Submission #130617

# Submission time Handle Problem Language Result Execution time Memory
130617 2019-07-15T18:13:33 Z RezwanArefin01 Amusement Park (JOI17_amusement_park) C++17
100 / 100
119 ms 35928 KB
#include <bits/stdc++.h>
#include "Joi.h"

using namespace std;

static const int N = 10010;
static const int B = 60;

static vector<int> adj[N], g[N]; 
static bitset<N> st[N]; 
static int vis[N], bit[N], p[N], comp[N], cnt, idx, deg[N]; 

void gen(int u) {
    vis[u] = 1; 
    for(int v : g[u]) if(!vis[v]) {
        adj[u].push_back(v); 
        adj[v].push_back(u);
        p[v] = u; 
        gen(v); 
    }
}

void mark(int u, int par = -1) {
    ++cnt; 
    st[0][u] = 1; 
    comp[u] = 0;
    bit[u] = cnt - 1;

    for(int v : adj[u]) if(v != par) {
        if(cnt < B) mark(v, u); 
        else break; 
    }
}

void dfs(int u, int par = -1) {
    int leaf = -1; 

    bitset<N> &S = st[comp[u]]; 
    vector<int> nodes;

    for(int i = S._Find_first(); i < S.size(); i = S._Find_next(i)) 
        deg[i] = 0, nodes.push_back(i); 

    for(int v : nodes) {
        if(!v) continue;
        if(S[p[v]]) {
            ++deg[p[v]]; 
            ++deg[v];
        }
    }

    for(int v : nodes) {
        if(deg[v] == 1 && v != u) {
            leaf = v; break; 
        }
    }

    for(int v : adj[u]) if(v != par) {
        if(comp[v] == -1) {
            comp[v] = ++idx;
            st[idx] = st[comp[u]]; 
            bit[v] = bit[leaf]; 
            st[idx][leaf] = 0; 
            st[idx][v] = 1; 
        } dfs(v, u);
    }
}

void Build(int n, int m, int A[], int B[]) {
    for(int i = 0; i < m; ++i) {
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    memset(comp, -1, sizeof comp); 

    gen(0);
    mark(0);
    dfs(0);
}  


void Joi(int n, int m, int A[], int B[], long long X, int T) {
    Build(n, m, A, B);

    for(int i = 0; i < n; ++i) {
        MessageBoard(i, X >> bit[i] & 1);
    }
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;

using namespace std;

static const int N = 10010;
static const int B = 60;

static vector<int> adj[N], g[N]; 
static bitset<N> st[N]; 
static int vis[N], bit[N], p[N], comp[N], cnt, idx, deg[N]; 

void gen(int u) {
    vis[u] = 1; 
    for(int v : g[u]) if(!vis[v]) {
        adj[u].push_back(v); 
        adj[v].push_back(u);
        p[v] = u; 
        gen(v); 
    }
}

void mark(int u, int par = -1) {
    ++cnt; 
    st[0][u] = 1; 
    comp[u] = 0;
    bit[u] = cnt - 1;

    for(int v : adj[u]) if(v != par) {
        if(cnt < B) mark(v, u); 
        else break; 
    }
}

void dfs(int u, int par = -1) {
    int leaf = -1; 

    bitset<N> &S = st[comp[u]]; 
    vector<int> nodes;

    for(int i = S._Find_first(); i < S.size(); i = S._Find_next(i)) 
        deg[i] = 0, nodes.push_back(i); 

    for(int v : nodes) {
        if(!v) continue;
        if(S[p[v]]) {
            ++deg[p[v]]; 
            ++deg[v];
        }
    }

    for(int v : nodes) {
        if(deg[v] == 1 && v != u) {
            leaf = v; break; 
        }
    }

    for(int v : adj[u]) if(v != par) {
        if(comp[v] == -1) {
            comp[v] = ++idx;
            st[idx] = st[comp[u]]; 
            bit[v] = bit[leaf]; 
            st[idx][leaf] = 0; 
            st[idx][v] = 1; 
        } dfs(v, u);
    }
}

void Build(int n, int m, int A[], int B[]) {
    for(int i = 0; i < m; ++i) {
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    memset(comp, -1, sizeof comp); 

    gen(0);
    mark(0);
    dfs(0);
}  

long long number, c; 

void visit(int u, long long x, int par = -1) {
    number |= x << bit[u];
    for(int v : adj[u]) if(v != par && st[c][v]) {
        visit(v, Move(v), u); 
    }
    if(par + 1) Move(par);
}

long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
    Build(n, m, A, B);

    c = comp[P]; 
    visit(P, V);
    return number;
}

Compilation message

Joi.cpp: In function 'void dfs(int, int)':
Joi.cpp:41:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = S._Find_first(); i < S.size(); i = S._Find_next(i)) 
                                  ~~^~~~~~~~~~

Ioi.cpp: In function 'void dfs(int, int)':
Ioi.cpp:42:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = S._Find_first(); i < S.size(); i = S._Find_next(i)) 
                                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2168 KB Output is correct
2 Correct 6 ms 2172 KB Output is correct
3 Correct 6 ms 2564 KB Output is correct
4 Correct 6 ms 2056 KB Output is correct
5 Correct 6 ms 2036 KB Output is correct
6 Correct 6 ms 2232 KB Output is correct
7 Correct 6 ms 2684 KB Output is correct
8 Correct 6 ms 2428 KB Output is correct
9 Correct 6 ms 2300 KB Output is correct
10 Correct 6 ms 2164 KB Output is correct
11 Correct 9 ms 2588 KB Output is correct
12 Correct 5 ms 1972 KB Output is correct
13 Correct 6 ms 2692 KB Output is correct
14 Correct 6 ms 2672 KB Output is correct
15 Correct 6 ms 2428 KB Output is correct
16 Correct 6 ms 2576 KB Output is correct
17 Correct 6 ms 2568 KB Output is correct
18 Correct 6 ms 2692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 31796 KB Output is correct
2 Correct 104 ms 31848 KB Output is correct
3 Correct 109 ms 31876 KB Output is correct
4 Correct 81 ms 28824 KB Output is correct
5 Correct 99 ms 31456 KB Output is correct
6 Correct 94 ms 29968 KB Output is correct
7 Correct 95 ms 30112 KB Output is correct
8 Correct 88 ms 30056 KB Output is correct
9 Correct 93 ms 30064 KB Output is correct
10 Correct 71 ms 29056 KB Output is correct
11 Correct 74 ms 29052 KB Output is correct
12 Correct 72 ms 26472 KB Output is correct
13 Correct 72 ms 26376 KB Output is correct
14 Correct 78 ms 27608 KB Output is correct
15 Correct 79 ms 28752 KB Output is correct
16 Correct 80 ms 28952 KB Output is correct
17 Correct 79 ms 28828 KB Output is correct
18 Correct 82 ms 28712 KB Output is correct
19 Correct 80 ms 28724 KB Output is correct
20 Correct 74 ms 32408 KB Output is correct
21 Correct 74 ms 32116 KB Output is correct
22 Correct 91 ms 29748 KB Output is correct
23 Correct 91 ms 29940 KB Output is correct
24 Correct 91 ms 29812 KB Output is correct
25 Correct 91 ms 30012 KB Output is correct
26 Correct 90 ms 30008 KB Output is correct
27 Correct 100 ms 30032 KB Output is correct
28 Correct 91 ms 30132 KB Output is correct
29 Correct 83 ms 27480 KB Output is correct
30 Correct 86 ms 28748 KB Output is correct
31 Correct 6 ms 2172 KB Output is correct
32 Correct 6 ms 2240 KB Output is correct
33 Correct 8 ms 2564 KB Output is correct
34 Correct 6 ms 2256 KB Output is correct
35 Correct 5 ms 2044 KB Output is correct
36 Correct 6 ms 2064 KB Output is correct
37 Correct 6 ms 2044 KB Output is correct
38 Correct 5 ms 1788 KB Output is correct
39 Correct 5 ms 1780 KB Output is correct
40 Correct 6 ms 2064 KB Output is correct
41 Correct 6 ms 2148 KB Output is correct
42 Correct 5 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2036 KB Output is correct
2 Correct 6 ms 2036 KB Output is correct
3 Correct 6 ms 2148 KB Output is correct
4 Correct 16 ms 7488 KB Output is correct
5 Correct 17 ms 7336 KB Output is correct
6 Correct 16 ms 7332 KB Output is correct
7 Correct 16 ms 7208 KB Output is correct
8 Correct 17 ms 7208 KB Output is correct
9 Correct 91 ms 35928 KB Output is correct
10 Correct 79 ms 35840 KB Output is correct
11 Correct 88 ms 35872 KB Output is correct
12 Correct 5 ms 1908 KB Output is correct
13 Correct 5 ms 1972 KB Output is correct
14 Correct 5 ms 1916 KB Output is correct
15 Correct 6 ms 1908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 31892 KB Output is correct
2 Correct 107 ms 31824 KB Output is correct
3 Correct 119 ms 31928 KB Output is correct
4 Correct 79 ms 28824 KB Output is correct
5 Correct 92 ms 33348 KB Output is correct
6 Correct 87 ms 30004 KB Output is correct
7 Correct 98 ms 30100 KB Output is correct
8 Correct 92 ms 29636 KB Output is correct
9 Correct 87 ms 29896 KB Output is correct
10 Correct 74 ms 29092 KB Output is correct
11 Correct 74 ms 28828 KB Output is correct
12 Correct 79 ms 26368 KB Output is correct
13 Correct 78 ms 26240 KB Output is correct
14 Correct 77 ms 27540 KB Output is correct
15 Correct 81 ms 28824 KB Output is correct
16 Correct 81 ms 28708 KB Output is correct
17 Correct 78 ms 28872 KB Output is correct
18 Correct 86 ms 28868 KB Output is correct
19 Correct 81 ms 28824 KB Output is correct
20 Correct 76 ms 32412 KB Output is correct
21 Correct 73 ms 32032 KB Output is correct
22 Correct 90 ms 30060 KB Output is correct
23 Correct 90 ms 29980 KB Output is correct
24 Correct 89 ms 29912 KB Output is correct
25 Correct 95 ms 29976 KB Output is correct
26 Correct 91 ms 29968 KB Output is correct
27 Correct 91 ms 30124 KB Output is correct
28 Correct 91 ms 29672 KB Output is correct
29 Correct 82 ms 27412 KB Output is correct
30 Correct 89 ms 28748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 31988 KB Output is correct
2 Correct 109 ms 31928 KB Output is correct
3 Correct 103 ms 31760 KB Output is correct
4 Correct 90 ms 28840 KB Output is correct
5 Correct 99 ms 34196 KB Output is correct
6 Correct 89 ms 29888 KB Output is correct
7 Correct 96 ms 29932 KB Output is correct
8 Correct 90 ms 30080 KB Output is correct
9 Correct 93 ms 30064 KB Output is correct
10 Correct 78 ms 28956 KB Output is correct
11 Correct 74 ms 29052 KB Output is correct
12 Correct 73 ms 26460 KB Output is correct
13 Correct 72 ms 26516 KB Output is correct
14 Correct 80 ms 27692 KB Output is correct
15 Correct 82 ms 28740 KB Output is correct
16 Correct 92 ms 28828 KB Output is correct
17 Correct 81 ms 28696 KB Output is correct
18 Correct 79 ms 28848 KB Output is correct
19 Correct 80 ms 28964 KB Output is correct
20 Correct 76 ms 32460 KB Output is correct
21 Correct 79 ms 32144 KB Output is correct
22 Correct 98 ms 29992 KB Output is correct
23 Correct 91 ms 29808 KB Output is correct
24 Correct 107 ms 30004 KB Output is correct
25 Correct 92 ms 29924 KB Output is correct
26 Correct 92 ms 29728 KB Output is correct
27 Correct 92 ms 30184 KB Output is correct
28 Correct 93 ms 30368 KB Output is correct
29 Correct 83 ms 27624 KB Output is correct
30 Correct 86 ms 28748 KB Output is correct
31 Correct 6 ms 2044 KB Output is correct
32 Correct 6 ms 2204 KB Output is correct
33 Correct 6 ms 2564 KB Output is correct
34 Correct 6 ms 2148 KB Output is correct
35 Correct 5 ms 2044 KB Output is correct
36 Correct 5 ms 1932 KB Output is correct
37 Correct 6 ms 2044 KB Output is correct
38 Correct 6 ms 1912 KB Output is correct
39 Correct 6 ms 1884 KB Output is correct
40 Correct 6 ms 2048 KB Output is correct
41 Correct 6 ms 2172 KB Output is correct
42 Correct 6 ms 1960 KB Output is correct