답안 #109995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109995 2019-05-08T15:02:23 Z popovicirobert Amusement Park (JOI17_amusement_park) C++14
10 / 100
3000 ms 263168 KB
#include "Joi.h"
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct DSU {

    vector <int> par;
    int n;

    inline void init(int _n) {
        n = _n;
        par.resize(n + 1, 0);
    }

    int root(int x) {
        if(par[x] == 0) return x;
        return par[x] = root(par[x]);
    }

    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] = y;
        }
    }

};

vector < vector <int> > g;

void make_mst(int n, int m, int A[], int B[]) {

    DSU dsu; dsu.init(n);
    g.resize(n);

    for(int i = 0; i < m; i++) {
        if(dsu.root(A[i]) != dsu.root(B[i])) {
            dsu.join(A[i], B[i]);
            g[A[i]].push_back(B[i]);
            g[B[i]].push_back(A[i]);
        }
    }

}

vector < vector <int> > group;
vector <int> bit;

static void dfs(int nod, int par, int &cur) {

    if(cur == 60) {
        return ;
    }

    bit[nod] = cur++;

    for(auto it : g[nod]) {
        if(it != par) {
            dfs(it, nod, cur);
        }
    }

}

vector <int> vis;
int now;

static void dfs1(int nod, int par) {

    if(bit[nod] == -1) {
        now++;
        for(auto it : group[par]) {
            vis[it] = now;
        }

        for(auto it : group[par]) {

            int cnt = 0;
            for(auto son : g[it]) {
                if(vis[son] == now) {
                    cnt++;
                }
            }

            if(cnt == 1 && it != par) {
                bit[nod] = bit[it];
                group[nod].push_back(nod);

                for(auto son : group[par]) {
                    if(son != it) {
                        group[nod].push_back(son);
                    }
                }

                break;
            }
        }
    }

    for(auto it : g[nod]) {
        if(it != par) {
            dfs1(it, nod);
        }
    }

}

void Joi(int N, int M, int A[], int B[], long long X, int T) {

    make_mst(N, M, A, B);

    bit.resize(N, -1);

    int cur = 0;
    dfs(0, -1, cur);

    group.resize(N);

    int i;
    for(i = 0; i < N; i++) {
        if(bit[i] > -1) {
            group[0].push_back(i);
        }
    }
    for(i = 1; i < N; i++) {
        if(bit[i] > -1) {
            group[i] = group[0];
        }
    }

    vis.resize(N);
    dfs1(0, -1);

    vector <bool> sol(N);
    for(i = 0; i < N; i++) {
        sol[i] = ((X & (1LL << bit[i])) > 0);
    }

    for(i = 0; i < N; i++) {
        MessageBoard(i, sol[i]);
    }

}
#include "Ioi.h"
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct DSU {

    vector <int> par;
    int n;

    inline void init(int _n) {
        n = _n;
        par.resize(n + 1, 0);
    }

    int root(int x) {
        if(par[x] == 0) return x;
        return par[x] = root(par[x]);
    }

    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] = y;
        }
    }

};

vector < vector <int> > g1;

static void make_mst(int n, int m, int A[], int B[]) {

    DSU dsu; dsu.init(n);
    g1.resize(n);

    for(int i = 0; i < m; i++) {
        if(dsu.root(A[i]) != dsu.root(B[i])) {
            dsu.join(A[i], B[i]);
            g1[A[i]].push_back(B[i]);
            g1[B[i]].push_back(A[i]);
        }
    }

}

vector < vector <int> > group1;
vector <int> bit1;

static void dfs(int nod, int par, int &cur) {

    if(cur == 60) {
        return ;
    }

    bit1[nod] = cur++;

    for(auto it : g1[nod]) {
        if(it != par) {
            dfs(it, nod, cur);
        }
    }

}

vector <int> vis1;
int now1;

static void dfs1(int nod, int par) {

    if(bit1[nod] == -1) {
        now1++;
        for(auto it : group1[par]) {
            vis1[it] = now1;
        }

        for(auto it : group1[par]) {

            int cnt = 0;
            for(auto son : g1[it]) {
                if(vis1[son] == now1) {
                    cnt++;
                }
            }

            if(cnt == 1 && it != par) {
                bit1[nod] = bit1[it];
                group1[nod].push_back(nod);

                for(auto son : group1[par]) {
                    if(son != it) {
                        group1[nod].push_back(son);
                    }
                }

                break;
            }
        }
    }

    for(auto it : g1[nod]) {
        if(it != par) {
            dfs1(it, nod);
        }
    }

}


void solve(int nod, ll &ans) {

    vis1[nod] = 0;

    for(auto it : g1[nod]) {
        if(vis1[it] == 1) {
            ans += Move(it) * (1LL << bit1[it]);

            solve(it, ans);

            Move(nod);
        }
    }

}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {

    make_mst(N, M, A, B);

    bit1.resize(N, -1);

    int cur = 0;
    dfs(0, -1, cur);

    group1.resize(N);

    int i;
    for(i = 0; i < N; i++) {
        if(bit1[i] > -1) {
            group1[0].push_back(i);
        }
    }

    for(i = 1; i < N; i++) {
        if(bit1[i] > -1) {
            group1[i] = group1[0];
        }
    }

    vis1.resize(N);
    dfs1(0, -1);

    fill(vis1.begin(), vis1.end(), 0);
    for(auto it : group1[P]) {
        vis1[it] = 1;
    }

    ll ans = V * (1LL << bit1[P]);
    solve(P, ans);

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1164 KB Output is correct
2 Correct 6 ms 968 KB Output is correct
3 Correct 6 ms 908 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 6 ms 896 KB Output is correct
6 Correct 4 ms 904 KB Output is correct
7 Correct 5 ms 1036 KB Output is correct
8 Correct 3 ms 900 KB Output is correct
9 Correct 5 ms 1036 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Runtime error 250 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1297 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 904 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 4 ms 896 KB Output is correct
4 Correct 11 ms 2420 KB Output is correct
5 Correct 13 ms 2420 KB Output is correct
6 Correct 12 ms 2468 KB Output is correct
7 Correct 9 ms 2416 KB Output is correct
8 Correct 8 ms 2452 KB Output is correct
9 Correct 39 ms 10416 KB Output is correct
10 Correct 42 ms 10432 KB Output is correct
11 Correct 38 ms 10332 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 4 ms 836 KB Output is correct
14 Correct 5 ms 904 KB Output is correct
15 Correct 4 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3016 ms 79092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3022 ms 92692 KB Time limit exceeded
2 Halted 0 ms 0 KB -