답안 #154528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154528 2019-09-22T13:52:02 Z Mercenary Amusement Park (JOI17_amusement_park) C++14
0 / 100
32 ms 4492 KB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;

void Joi(int N, int M, int A[], int B[], long long X, int T) {
    const static int maxn = 1e4 + 5;
    static int lab[maxn];
    static int nTime = 0;
    static int id[maxn];
    static long long res = 0;
    static long long cal = 0;
    static vector<int> adj[maxn];
    fill_n(lab,maxn,-1);
    function<int(int)> FindLab = [&](int u){
        return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);
    };
    for(int i = 0 ; i < M ; ++i){
        int s = FindLab(A[i]);
        int d = FindLab(B[i]);
        if(s != d){
            if(lab[s] > lab[d])swap(s , d);
            lab[s] += lab[d];
            lab[d] = s;
            adj[A[i]].push_back(B[i]);
            adj[B[i]].push_back(A[i]);
        }
    }
    function<void(int,int)> DFS = [&](int u , int par){
        id[u] = nTime;
        ++nTime;
        for(int c : adj[u]){
            if(c != par){
                DFS(c , u);
            }
        }
    };
    DFS(0 , -1);
    for(int i = 0 ; i < N ; ++i){
        MessageBoard(i , (X >> id[i]) & 1);
    }
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    const static int maxn = 1e4 + 5;
    static int lab[maxn];
    static int nTime = 0;
    static int id[maxn];
    static long long res = 0;
    static long long cal = 0;
    static int sub[maxn] , h[maxn];
    static long long can[maxn];
    static int p[maxn];
    static vector<int> adj[maxn];
    static vector<int> child[maxn];
    fill_n(lab,maxn,-1);
    function<int(int)> FindLab = [&](int u){
        return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);
    };
    for(int i = 0 ; i < M ; ++i){
        int s = FindLab(A[i]);
        int d = FindLab(B[i]);
        if(s != d){
            lab[s] += lab[d];
            lab[d] = s;
            adj[A[i]].push_back(B[i]);
            adj[B[i]].push_back(A[i]);
        }
    }
    function<void(int,int)> DFS = [&](int u , int par){
        id[u] = nTime;
        can[u] = (1ll << nTime);
        ++nTime;
        sub[u] = 1;
        for(int c : adj[u]){
            if(c != par){
                child[u].push_back(c);
                p[c] = u;
                DFS(c , u);
                h[u] = max(h[u] , h[c] + 1);
                sub[u] += sub[c];
                can[u] |= can[c];
            }
        }
    };
    DFS(0 , -1);
    function<void(int)> DFS2 = [&](int u){
        cal |= (1ll << id[u]);
        if(V)res |= (1ll << id[u]);
        for(int c : child[u]){
            if(__builtin_popcountll(cal) == 60)return;
            if((~cal) & can[c]){
                V = Move(c);
                DFS2(c);
                V = Move(u);
            }
        }
    };
    function<void(int)> DFS1 = [&](int u){
        cal |= (1ll << id[u]);
        if(V)res |= (1ll << id[u]);
        if(child[u].empty())return;
        int best = -1;
        for(int i = 0 ; i < (int)child[u].size() ; ++i){
            if(__builtin_popcountll(cal) == 60)return;
            int c = child[u][i];
            if((~cal) & can[c]){
                if(best == -1 || h[best] < h[c])best = c;
            }
        }
        for(int i = 0 ; i < (int)child[u].size() ; ++i){
            if(__builtin_popcountll(cal) == 60)return;
            int c = child[u][i];
            if(c == best)continue;
            if((~cal) & can[c]){
                V = Move(c);
                DFS2(c);
                V = Move(u);
            }
        }
        if(best != -1 && ((~cal) & can[best])){
            V = Move(best);
            DFS1(best);
        }
    };
    while(sub[P] < 60){
        cal |= (1ll << id[P]);
        if(V)res |= (1ll << id[P]);
        V = Move(p[P]);
        P = p[P];
    }
    DFS1(P);
//    cout << bitset<60>(cal);
    return res;
}

Compilation message

Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:10:22: warning: unused variable 'res' [-Wunused-variable]
     static long long res = 0;
                      ^~~
Joi.cpp:11:22: warning: unused variable 'cal' [-Wunused-variable]
     static long long cal = 0;
                      ^~~
Joi.cpp: At global scope:
Joi.cpp:11:22: warning: 'cal' defined but not used [-Wunused-variable]
Joi.cpp:10:22: warning: 'res' defined but not used [-Wunused-variable]
     static long long res = 0;
                      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1652 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 4492 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1524 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 31 ms 4352 KB Partially correct
2 Incorrect 32 ms 4372 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 4304 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -