답안 #68887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68887 2018-08-19T00:59:52 Z duality Amusement Park (JOI17_amusement_park) C++14
100 / 100
109 ms 15688 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "Joi.h"

static int parent[10000];
static int find(int n) {
    if (parent[n] != n) parent[n] = find(parent[n]);
    return parent[n];
}
static vpii edges;
static vi adjList[10000];
static vpii sub[10000];
static int num[10000];
static int doDFS(int u,int p) {
    int i;
    if (sub[0].size() < 60) num[u] = sub[0].size(),sub[0].pb(mp(u,0));
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS(v,u);
    }
    return 0;
}
static int doDFS2(int u,int p) {
    int i;
    if (p != -1) {
        for (i = 0; i < 60; i++) {
            if (sub[p][i].first == u) break;
        }
        sub[u] = sub[p];
        if (i == 60) {
            for (i = 0; i < 60; i++) {
                if ((sub[u][i].first != p) && (sub[u][i].second == 1)) break;
            }
            int x = i;
            for (i = 0; i < 60; i++) {
                if (sub[u][i].first == p) {
                    sub[u][i].second++;
                    break;
                }
            }
            for (i = 0; i < 60; i++) {
                if (binary_search(edges.begin(),edges.end(),mp(sub[u][x].first,sub[u][i].first))) {
                    sub[u][i].second--;
                    break;
                }
            }
            num[u] = num[sub[u][x].first];
            sub[u][x].first = u;
        }
    }
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS2(v,u);
    }
    return 0;
}
void Joi(int N,int M,int A[],int B[],long long int X,int T) {
    int i;
    for (i = 0; i < N; i++) parent[i] = i;
    for (i = 0; i < M; i++) {
        int pa = find(A[i]),pb = find(B[i]);
        if (pa != pb) {
            parent[pa] = pb;
            adjList[A[i]].pb(B[i]);
            adjList[B[i]].pb(A[i]);
            edges.pb(mp(A[i],B[i]));
            edges.pb(mp(B[i],A[i]));
        }
    }
    sort(edges.begin(),edges.end());
    int j,k;
    doDFS(0,-1);
    for (i = 0; i < 60; i++) {
        for (j = 0; j < adjList[sub[0][i].first].size(); j++) {
            for (k = 0; k < 60; k++) {
                if (adjList[sub[0][i].first][j] == sub[0][k].first) sub[0][i].second++;
            }
        }
    }
    doDFS2(0,-1);
    for (i = 0; i < N; i++) MessageBoard(i,(X & (1LL << num[i])) > 0);
}
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "Ioi.h"

static int parent[10000];
static int find(int n) {
    if (parent[n] != n) parent[n] = find(parent[n]);
    return parent[n];
}
static vpii edges;
static vi adjList[10000];
static vpii sub[10000];
static int num[10000];
static int doDFS(int u,int p) {
    int i;
    if (sub[0].size() < 60) num[u] = sub[0].size(),sub[0].pb(mp(u,0));
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS(v,u);
    }
    return 0;
}
static int doDFS2(int u,int p) {
    int i;
    if (p != -1) {
        for (i = 0; i < 60; i++) {
            if (sub[p][i].first == u) break;
        }
        sub[u] = sub[p];
        if (i == 60) {
            for (i = 0; i < 60; i++) {
                if ((sub[u][i].first != p) && (sub[u][i].second == 1)) break;
            }
            int x = i;
            for (i = 0; i < 60; i++) {
                if (sub[u][i].first == p) {
                    sub[u][i].second++;
                    break;
                }
            }
            for (i = 0; i < 60; i++) {
                if (binary_search(edges.begin(),edges.end(),mp(sub[u][x].first,sub[u][i].first))) {
                    sub[u][i].second--;
                    break;
                }
            }
            num[u] = num[sub[u][x].first];
            sub[u][x].first = u;
        }
    }
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS2(v,u);
    }
    return 0;
}
static LLI ans = 0;
static int insub[10000],message[10000];
static int doDFS3(int u,int p) {
    int i;
    if (message[u]) ans |= (1LL << num[u]);
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if ((v != p) && insub[v]) {
            message[v] = Move(v);
            doDFS3(v,u);
            Move(u);
        }
    }
    return 0;
}
long long int Ioi(int N,int M,int A[],int B[],int P,int V,int T) {
    int i;
    for (i = 0; i < N; i++) parent[i] = i;
    for (i = 0; i < M; i++) {
        int pa = find(A[i]),pb = find(B[i]);
        if (pa != pb) {
            parent[pa] = pb;
            adjList[A[i]].pb(B[i]);
            adjList[B[i]].pb(A[i]);
            edges.pb(mp(A[i],B[i]));
            edges.pb(mp(B[i],A[i]));
        }
    }
    sort(edges.begin(),edges.end());
    int j,k;
    doDFS(0,-1);
    for (i = 0; i < 60; i++) {
        for (j = 0; j < adjList[sub[0][i].first].size(); j++) {
            for (k = 0; k < 60; k++) {
                if (adjList[sub[0][i].first][j] == sub[0][k].first) sub[0][i].second++;
            }
        }
    }
    doDFS2(0,-1);
    for (i = 0; i < 60; i++) insub[sub[P][i].first] = 1;
    message[P] = V;
    doDFS3(P,-1);
    return ans;
}

Compilation message

Joi.cpp: In function 'int doDFS(int, int)':
Joi.cpp:71:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
Joi.cpp: In function 'int doDFS2(int, int)':
Joi.cpp:105:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:128:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[sub[0][i].first].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ioi.cpp: In function 'int doDFS(int, int)':
Ioi.cpp:71:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'int doDFS2(int, int)':
Ioi.cpp:105:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'int doDFS3(int, int)':
Ioi.cpp:116:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:143:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[sub[0][i].first].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1760 KB Output is correct
2 Correct 6 ms 2072 KB Output is correct
3 Correct 7 ms 2436 KB Output is correct
4 Correct 6 ms 2440 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 6 ms 2440 KB Output is correct
7 Correct 8 ms 2636 KB Output is correct
8 Correct 10 ms 2688 KB Output is correct
9 Correct 7 ms 2736 KB Output is correct
10 Correct 6 ms 2752 KB Output is correct
11 Correct 10 ms 2752 KB Output is correct
12 Correct 6 ms 2752 KB Output is correct
13 Correct 7 ms 2860 KB Output is correct
14 Correct 6 ms 2968 KB Output is correct
15 Correct 8 ms 2968 KB Output is correct
16 Correct 6 ms 2968 KB Output is correct
17 Correct 7 ms 2968 KB Output is correct
18 Correct 10 ms 2968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 14620 KB Output is correct
2 Correct 84 ms 14688 KB Output is correct
3 Correct 109 ms 14688 KB Output is correct
4 Correct 69 ms 14688 KB Output is correct
5 Correct 99 ms 14688 KB Output is correct
6 Correct 86 ms 14688 KB Output is correct
7 Correct 88 ms 14688 KB Output is correct
8 Correct 101 ms 14808 KB Output is correct
9 Correct 80 ms 14808 KB Output is correct
10 Correct 53 ms 14808 KB Output is correct
11 Correct 55 ms 14808 KB Output is correct
12 Correct 57 ms 14808 KB Output is correct
13 Correct 57 ms 14808 KB Output is correct
14 Correct 53 ms 14808 KB Output is correct
15 Correct 63 ms 14808 KB Output is correct
16 Correct 60 ms 14808 KB Output is correct
17 Correct 48 ms 14808 KB Output is correct
18 Correct 63 ms 14808 KB Output is correct
19 Correct 48 ms 14808 KB Output is correct
20 Correct 61 ms 14856 KB Output is correct
21 Correct 59 ms 14904 KB Output is correct
22 Correct 81 ms 14904 KB Output is correct
23 Correct 83 ms 14904 KB Output is correct
24 Correct 81 ms 14904 KB Output is correct
25 Correct 80 ms 14904 KB Output is correct
26 Correct 94 ms 14904 KB Output is correct
27 Correct 86 ms 14904 KB Output is correct
28 Correct 88 ms 14904 KB Output is correct
29 Correct 87 ms 14904 KB Output is correct
30 Correct 88 ms 14904 KB Output is correct
31 Correct 6 ms 14904 KB Output is correct
32 Correct 6 ms 14904 KB Output is correct
33 Correct 9 ms 14904 KB Output is correct
34 Correct 7 ms 14904 KB Output is correct
35 Correct 6 ms 14904 KB Output is correct
36 Correct 7 ms 14904 KB Output is correct
37 Correct 5 ms 14904 KB Output is correct
38 Correct 6 ms 14904 KB Output is correct
39 Correct 6 ms 14904 KB Output is correct
40 Correct 7 ms 14904 KB Output is correct
41 Correct 6 ms 14904 KB Output is correct
42 Correct 7 ms 14904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14904 KB Output is correct
2 Correct 7 ms 14904 KB Output is correct
3 Correct 6 ms 14904 KB Output is correct
4 Correct 15 ms 14904 KB Output is correct
5 Correct 15 ms 14904 KB Output is correct
6 Correct 17 ms 14904 KB Output is correct
7 Correct 13 ms 14904 KB Output is correct
8 Correct 17 ms 14904 KB Output is correct
9 Correct 53 ms 15376 KB Output is correct
10 Correct 56 ms 15412 KB Output is correct
11 Correct 51 ms 15448 KB Output is correct
12 Correct 6 ms 15448 KB Output is correct
13 Correct 8 ms 15448 KB Output is correct
14 Correct 5 ms 15448 KB Output is correct
15 Correct 6 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 15448 KB Output is correct
2 Correct 76 ms 15448 KB Output is correct
3 Correct 84 ms 15448 KB Output is correct
4 Correct 52 ms 15448 KB Output is correct
5 Correct 83 ms 15448 KB Output is correct
6 Correct 84 ms 15448 KB Output is correct
7 Correct 86 ms 15448 KB Output is correct
8 Correct 82 ms 15448 KB Output is correct
9 Correct 82 ms 15448 KB Output is correct
10 Correct 48 ms 15448 KB Output is correct
11 Correct 49 ms 15448 KB Output is correct
12 Correct 54 ms 15448 KB Output is correct
13 Correct 49 ms 15448 KB Output is correct
14 Correct 52 ms 15448 KB Output is correct
15 Correct 51 ms 15448 KB Output is correct
16 Correct 52 ms 15448 KB Output is correct
17 Correct 61 ms 15448 KB Output is correct
18 Correct 61 ms 15448 KB Output is correct
19 Correct 57 ms 15448 KB Output is correct
20 Correct 64 ms 15448 KB Output is correct
21 Correct 59 ms 15448 KB Output is correct
22 Correct 76 ms 15448 KB Output is correct
23 Correct 78 ms 15448 KB Output is correct
24 Correct 92 ms 15448 KB Output is correct
25 Correct 87 ms 15448 KB Output is correct
26 Correct 98 ms 15448 KB Output is correct
27 Correct 91 ms 15448 KB Output is correct
28 Correct 86 ms 15448 KB Output is correct
29 Correct 82 ms 15448 KB Output is correct
30 Correct 75 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 15448 KB Output is correct
2 Correct 97 ms 15448 KB Output is correct
3 Correct 93 ms 15448 KB Output is correct
4 Correct 54 ms 15448 KB Output is correct
5 Correct 78 ms 15568 KB Output is correct
6 Correct 73 ms 15688 KB Output is correct
7 Correct 80 ms 15688 KB Output is correct
8 Correct 71 ms 15688 KB Output is correct
9 Correct 78 ms 15688 KB Output is correct
10 Correct 51 ms 15688 KB Output is correct
11 Correct 40 ms 15688 KB Output is correct
12 Correct 62 ms 15688 KB Output is correct
13 Correct 49 ms 15688 KB Output is correct
14 Correct 55 ms 15688 KB Output is correct
15 Correct 51 ms 15688 KB Output is correct
16 Correct 46 ms 15688 KB Output is correct
17 Correct 56 ms 15688 KB Output is correct
18 Correct 59 ms 15688 KB Output is correct
19 Correct 64 ms 15688 KB Output is correct
20 Correct 53 ms 15688 KB Output is correct
21 Correct 62 ms 15688 KB Output is correct
22 Correct 78 ms 15688 KB Output is correct
23 Correct 81 ms 15688 KB Output is correct
24 Correct 73 ms 15688 KB Output is correct
25 Correct 80 ms 15688 KB Output is correct
26 Correct 75 ms 15688 KB Output is correct
27 Correct 74 ms 15688 KB Output is correct
28 Correct 82 ms 15688 KB Output is correct
29 Correct 75 ms 15688 KB Output is correct
30 Correct 76 ms 15688 KB Output is correct
31 Correct 6 ms 15688 KB Output is correct
32 Correct 7 ms 15688 KB Output is correct
33 Correct 7 ms 15688 KB Output is correct
34 Correct 7 ms 15688 KB Output is correct
35 Correct 6 ms 15688 KB Output is correct
36 Correct 6 ms 15688 KB Output is correct
37 Correct 6 ms 15688 KB Output is correct
38 Correct 6 ms 15688 KB Output is correct
39 Correct 6 ms 15688 KB Output is correct
40 Correct 6 ms 15688 KB Output is correct
41 Correct 7 ms 15688 KB Output is correct
42 Correct 6 ms 15688 KB Output is correct