답안 #122846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122846 2019-06-29T11:00:04 Z songc Amusement Park (JOI17_amusement_park) C++14
0 / 100
35 ms 4800 KB
#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

static int N, M;
static vector<int> adj[10101];
static int C[10101], num;
static set<int> G[10101];
static queue<pii> Q;

static void dfs(int u){
    if (C[u] != -1) return;
    if (num >= 60) return;
    C[u] = num++;
    for (int v : adj[u]) dfs(v);
}

static LL Color(int u, int r, int x, LL chk){
    if (C[u] == -1) return chk;
    if (chk & (1ll << C[u])) return chk;
    if (__builtin_popcountl(chk) == 59) return chk;
    if (G[x].find(u) == G[x].end()) return chk;
    chk |= 1ll << C[u];
    G[r].insert(u);
    for (int v : adj[u]) chk = Color(v, r, x, chk);
    return chk;
}

void Joi(int n, int m, int A[], int B[], long long X, int T) {
    N=n, M=m;
    for (int i=0; i<M; i++){
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    memset(C, -1, sizeof C);
    dfs(0);
    for (int i=0; i<N; i++){
        if (C[i] == -1) continue;
        for (int j=0; j<N; j++) if (C[j] != -1) G[i].insert(j);
        for (int j : adj[i]) Q.push(pii(i, j));
    }
    while (!Q.empty()){
        pii t = Q.front();
        Q.pop();
        if (C[t.first]) continue;
        LL chk = 0;
        chk = Color(t.second, t.first, t.second, chk);
        G[t.first].insert(t.first);
        for (int i=0; i<60; i++) if (~chk & (1ll<<i)) C[t.first] = i;
        for (int v : adj[t.first]) Q.push(pii(v, t.first));
    }
    for (int i=0; i<N; i++) MessageBoard(i, (X & (1ll << C[i])) ? 1 : 0);
}
#include <bits/stdc++.h>
#include "Ioi.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

static int N, M;
static vector<int> adj[10101];
static int C[10101], num;
static set<int> G[10101];
static LL ans;
static queue<pii> Q;

static void dfs(int u){
    if (C[u] != -1) return;
    if (num >= 60) return;
    C[u] = num++;
    for (int v : adj[u]) dfs(v);
}

static LL Color(int u, int r, int x, LL chk){
    if (C[u] == -1) return chk;
    if (chk & (1ll << C[u])) return chk;
    if (__builtin_popcountl(chk) == 59) return chk;
    if (G[x].find(u) == G[x].end()) return chk;
    chk |= 1ll << C[u];
    G[r].insert(u);
    for (int v : adj[u]) chk = Color(v, r, x, chk);
    return chk;
}

static LL Findans(int u, int p, int x, LL chk){
    if (C[u] == -1) return chk;
    if (chk & (1ll << C[u])) return chk;
    if (G[x].find(u) == G[x].end()) return chk;
    chk |= 1ll << C[u];
    if (p != -1) ans |= (LL)Move(u) << C[u];
    for (int v : adj[u]) chk = Findans(v, u, x, chk);
    if (p != -1) Move(p);
    return chk;
}

long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
    N=n, M=m;
    for (int i=0; i<M; i++){
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    memset(C, -1, sizeof C);
    dfs(0);
    for (int i=0; i<N; i++){
        if (C[i] == -1) continue;
        for (int j=0; j<N; j++) if (C[j] != -1) G[i].insert(j);
        for (int j : adj[i]) Q.push(pii(i, j));
    }
    while (!Q.empty()){
        pii t = Q.front();
        Q.pop();
        if (C[t.first]) continue;
        LL chk = 0;
        chk = Color(t.second, t.first, t.second, chk);
        G[t.first].insert(t.first);
        for (int i=0; i<60; i++) if (~chk & (1ll<<i)) C[t.first] = i;
        for (int v : adj[t.first]) Q.push(pii(v, t.first));
    }

    Findans(P, -1, P, 0);
    ans |= (LL)V << C[P];
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2544 KB Output is correct
2 Incorrect 6 ms 2676 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4800 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2548 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Incorrect 6 ms 2684 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4800 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4676 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -