답안 #418808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418808 2021-06-05T22:39:41 Z Osama_Alkhodairy Amusement Park (JOI17_amusement_park) C++17
100 / 100
26 ms 4108 KB
#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
#define ll long long

const int NA = 10001;
const int KA = 60;

int mxA[NA], pA[NA], tA[NA], dfstimeA;
vector <int> vA[NA];

int findA(int x){
    if(pA[x] == x) return x;
    return pA[x] = findA(pA[x]);
}
bool mergeA(int x, int y){
    x = findA(x);
    y = findA(y);
    if(x == y) return 0;
    pA[x] = y;
    return 1;
}
void dfszA(int node, int pnode){
    for(auto &i : vA[node]){
        if(i == pnode) continue;
        dfszA(i, node);
        mxA[node] = max(mxA[node], mxA[i] + 1);
    }
}
void dfsA(int node, int pnode){
    tA[node] = dfstimeA++;
    for(auto &i : vA[node]){
        if(i == pnode) continue;
        dfsA(i, node);
    }
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
    for(int i = 0 ; i < N ; i++){
        pA[i] = i;
    }
    for(int i = 0 ; i < M ; i++){
        if(mergeA(A[i], B[i])){
            vA[A[i]].push_back(B[i]);
            vA[B[i]].push_back(A[i]);
        }
    }
    dfszA(0, 0);
    for(int i = 0 ; i < N ; i++){
        sort(vA[i].begin(), vA[i].end(), [&](int l, int r){
            return mxA[l] > mxA[r];
        });
    }
    dfsA(0, 0);
    for(int i = 0 ; i < N ; i++){
        MessageBoard(i, (X >> (tA[i] % KA)) & 1);
    }
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
#define ll long long

const int NB = 10001;
const int KB = 60;

int mxB[NB], pB[NB], tB[NB], szB[NB], XB[KB], unknownB = KB, dfstimeB;
vector <int> vB[NB];

void updateB(int bit, int v){
    if(XB[bit] == -1){
        unknownB--;
        XB[bit] = v;
    }
}
int findB(int x){
    if(pB[x] == x) return x;
    return pB[x] = findB(pB[x]);
}
bool mergeB(int x, int y){
    x = findB(x);
    y = findB(y);
    if(x == y) return 0;
    pB[x] = y;
    return 1;
}
void dfszB(int node, int pnode){
    for(auto &i : vB[node]){
        if(i == pnode) continue;
        dfszB(i, node);
        mxB[node] = max(mxB[node], mxB[i] + 1);
    }
}
void dfsB(int node, int pnode){
    szB[node] = 1;
    tB[node] = dfstimeB++;
    for(auto &i : vB[node]){
        if(i == pnode) continue;
        pB[i] = node;
        dfsB(i, node);
        szB[node] += szB[i];
    }
}
void my_moveB(int dest){
    int v = Move(dest);
    assert(0 <= v && v <= 1);
    updateB(tB[dest] % KB, v);
}
void solveB(int node, int k){
    if(unknownB == 0) return;
    k--;
    vector <int> all;
    for(auto &i : vB[node]){
        if(unknownB == 0) return;
        if(k == 0) break;
        if(k < szB[i]){
            my_moveB(i);
            solveB(i, k);
            break;
        }
        else{
            all.push_back(i);
            k -= szB[i];
        }
    }
    reverse(all.begin(), all.end());
    for(auto &i : all){
        if(unknownB == 0) return;
        my_moveB(i);
        solveB(i, szB[i]);
    }
    if(unknownB == 0) return;
    if(pB[node] != -1) my_moveB(pB[node]);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    for(int i = 0 ; i < KB ; i++){
        XB[i] = -1;
    }
    for(int i = 0 ; i < N ; i++){
        pB[i] = i;
    }
    for(int i = 0 ; i < M ; i++){
        if(mergeB(A[i], B[i])){
            vB[A[i]].push_back(B[i]);
            vB[B[i]].push_back(A[i]);
        }
    }
    dfszB(0, 0);
    for(int i = 0 ; i < N ; i++){
        sort(vB[i].begin(), vB[i].end(), [&](int l, int r){
            return mxB[l] > mxB[r];
        });
    }
    pB[0] = -1;
    dfsB(0, 0);
    for(int i = 1 ; i < N ; i++){
        vB[i].erase(find(vB[i].begin(), vB[i].end(), pB[i]));
    }
    int node = P;
    int v = V;
    updateB(tB[node] % KB, v);
    while(szB[node] < KB){
        my_moveB(pB[node]);
        node = pB[node];
    }
    solveB(node, KB);
    ll X = 0;
    for(int i = KB - 1 ; i >= 0 ; i--){
        X = 2 * X + XB[i];
    }
    return X;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1012 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1008 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1012 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 2 ms 1008 KB Output is correct
9 Correct 2 ms 1008 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 5 ms 1332 KB Output is correct
12 Correct 2 ms 1004 KB Output is correct
13 Correct 2 ms 1008 KB Output is correct
14 Correct 2 ms 1008 KB Output is correct
15 Correct 2 ms 1016 KB Output is correct
16 Correct 2 ms 1008 KB Output is correct
17 Correct 2 ms 1008 KB Output is correct
18 Correct 2 ms 1008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3704 KB Output is correct
2 Correct 25 ms 3680 KB Output is correct
3 Correct 25 ms 3660 KB Output is correct
4 Correct 16 ms 2844 KB Output is correct
5 Correct 18 ms 3484 KB Output is correct
6 Correct 18 ms 3324 KB Output is correct
7 Correct 17 ms 3364 KB Output is correct
8 Correct 16 ms 3336 KB Output is correct
9 Correct 17 ms 3464 KB Output is correct
10 Correct 15 ms 3080 KB Output is correct
11 Correct 15 ms 3016 KB Output is correct
12 Correct 16 ms 2808 KB Output is correct
13 Correct 15 ms 2804 KB Output is correct
14 Correct 18 ms 2816 KB Output is correct
15 Correct 16 ms 2828 KB Output is correct
16 Correct 17 ms 2900 KB Output is correct
17 Correct 17 ms 2808 KB Output is correct
18 Correct 16 ms 2916 KB Output is correct
19 Correct 16 ms 2828 KB Output is correct
20 Correct 13 ms 3592 KB Output is correct
21 Correct 14 ms 3596 KB Output is correct
22 Correct 16 ms 3192 KB Output is correct
23 Correct 16 ms 3416 KB Output is correct
24 Correct 18 ms 3452 KB Output is correct
25 Correct 17 ms 3300 KB Output is correct
26 Correct 16 ms 3340 KB Output is correct
27 Correct 16 ms 3336 KB Output is correct
28 Correct 16 ms 3372 KB Output is correct
29 Correct 15 ms 3168 KB Output is correct
30 Correct 16 ms 3324 KB Output is correct
31 Correct 2 ms 1008 KB Output is correct
32 Correct 2 ms 1008 KB Output is correct
33 Correct 2 ms 1008 KB Output is correct
34 Correct 2 ms 1000 KB Output is correct
35 Correct 2 ms 1016 KB Output is correct
36 Correct 2 ms 1012 KB Output is correct
37 Correct 2 ms 1004 KB Output is correct
38 Correct 2 ms 1012 KB Output is correct
39 Correct 2 ms 1004 KB Output is correct
40 Correct 2 ms 1012 KB Output is correct
41 Correct 2 ms 1092 KB Output is correct
42 Correct 1 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1000 KB Output is correct
2 Correct 2 ms 1000 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 3 ms 1556 KB Output is correct
5 Correct 4 ms 1556 KB Output is correct
6 Correct 3 ms 1556 KB Output is correct
7 Correct 3 ms 1560 KB Output is correct
8 Correct 3 ms 1568 KB Output is correct
9 Correct 14 ms 4068 KB Output is correct
10 Correct 14 ms 4088 KB Output is correct
11 Correct 14 ms 4108 KB Output is correct
12 Correct 1 ms 1012 KB Output is correct
13 Correct 2 ms 1012 KB Output is correct
14 Correct 2 ms 1004 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3680 KB Output is correct
2 Correct 26 ms 3708 KB Output is correct
3 Correct 26 ms 3684 KB Output is correct
4 Correct 16 ms 2884 KB Output is correct
5 Correct 17 ms 3940 KB Output is correct
6 Correct 19 ms 3344 KB Output is correct
7 Correct 17 ms 3364 KB Output is correct
8 Correct 16 ms 3148 KB Output is correct
9 Correct 16 ms 3332 KB Output is correct
10 Correct 14 ms 3084 KB Output is correct
11 Correct 15 ms 3072 KB Output is correct
12 Correct 15 ms 2728 KB Output is correct
13 Correct 14 ms 2760 KB Output is correct
14 Correct 16 ms 2812 KB Output is correct
15 Correct 16 ms 2828 KB Output is correct
16 Correct 16 ms 2920 KB Output is correct
17 Correct 16 ms 2816 KB Output is correct
18 Correct 16 ms 2928 KB Output is correct
19 Correct 16 ms 2828 KB Output is correct
20 Correct 15 ms 3596 KB Output is correct
21 Correct 12 ms 3592 KB Output is correct
22 Correct 16 ms 3328 KB Output is correct
23 Correct 16 ms 3328 KB Output is correct
24 Correct 16 ms 3288 KB Output is correct
25 Correct 16 ms 3340 KB Output is correct
26 Correct 16 ms 3344 KB Output is correct
27 Correct 16 ms 3476 KB Output is correct
28 Correct 16 ms 3320 KB Output is correct
29 Correct 15 ms 3288 KB Output is correct
30 Correct 17 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3244 KB Output is correct
2 Correct 26 ms 3292 KB Output is correct
3 Correct 26 ms 3628 KB Output is correct
4 Correct 16 ms 2920 KB Output is correct
5 Correct 17 ms 3996 KB Output is correct
6 Correct 16 ms 3300 KB Output is correct
7 Correct 18 ms 3332 KB Output is correct
8 Correct 16 ms 3320 KB Output is correct
9 Correct 18 ms 3288 KB Output is correct
10 Correct 16 ms 3072 KB Output is correct
11 Correct 16 ms 3004 KB Output is correct
12 Correct 14 ms 2800 KB Output is correct
13 Correct 15 ms 2808 KB Output is correct
14 Correct 16 ms 2804 KB Output is correct
15 Correct 16 ms 2840 KB Output is correct
16 Correct 16 ms 3016 KB Output is correct
17 Correct 16 ms 2932 KB Output is correct
18 Correct 16 ms 2808 KB Output is correct
19 Correct 16 ms 2896 KB Output is correct
20 Correct 14 ms 3604 KB Output is correct
21 Correct 12 ms 3600 KB Output is correct
22 Correct 16 ms 3344 KB Output is correct
23 Correct 16 ms 3280 KB Output is correct
24 Correct 16 ms 3228 KB Output is correct
25 Correct 16 ms 3320 KB Output is correct
26 Correct 16 ms 3340 KB Output is correct
27 Correct 16 ms 3596 KB Output is correct
28 Correct 23 ms 3464 KB Output is correct
29 Correct 16 ms 3280 KB Output is correct
30 Correct 16 ms 3312 KB Output is correct
31 Correct 2 ms 1080 KB Output is correct
32 Correct 2 ms 1004 KB Output is correct
33 Correct 2 ms 1136 KB Output is correct
34 Correct 2 ms 1000 KB Output is correct
35 Correct 2 ms 1004 KB Output is correct
36 Correct 2 ms 1012 KB Output is correct
37 Correct 2 ms 1008 KB Output is correct
38 Correct 2 ms 1000 KB Output is correct
39 Correct 2 ms 1004 KB Output is correct
40 Correct 2 ms 1084 KB Output is correct
41 Correct 2 ms 1012 KB Output is correct
42 Correct 2 ms 1016 KB Output is correct