답안 #126246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126246 2019-07-07T10:02:42 Z arnold518 Amusement Park (JOI17_amusement_park) C++14
10 / 100
51 ms 6828 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e4;

static int N, M;
static vector<int> adj[MAXN+10], tree[MAXN+10];
static int num[MAXN+10], cnt=0;
static int par[MAXN+10], deg[MAXN+10], col[MAXN+10];
static bool live[MAXN+10];

static void dfs1(int now)
{
    num[now]=cnt++;
    if(num[now]<60)
    {
        live[now]=true;
        col[now]=num[now];
    }

    for(int nxt : adj[now])
    {
        if(num[nxt]!=-1) continue;
        dfs1(nxt);

        if(num[now]<60 && num[nxt]<60) deg[now]++, deg[nxt]++;
        tree[now].push_back(nxt);
        tree[nxt].push_back(now);
        par[nxt]=now;
    }
}

static bool vis[MAXN+10];
static set<int> S;
static void dfs2(int now)
{
    vis[now]=true;

    int leaf;
    vector<int> V;
    if(num[now]>=60)
    {
        for(auto it : S) if(it!=par[now]) { leaf=it; break; }
        S.erase(leaf);
        live[leaf]=false; col[now]=col[leaf];
        for(int nxt : tree[leaf])
        {
            if(!live[nxt]) continue;
            V.push_back(nxt);
            deg[leaf]--;
            deg[nxt]--;
            if(deg[nxt]==1) S.insert(nxt);
        }
        live[now]=true;
        deg[par[now]]++;
        deg[now]++;
        S.insert(now);
    }

    for(int nxt : tree[now])
    {
        if(vis[nxt]) continue;
        dfs2(nxt);
    }

    if(num[now]>=60)
    {
        deg[par[now]]--;
        deg[now]--;
        S.erase(now);
        S.insert(leaf);
        live[leaf]=true;
        live[now]=false;
        for(int it : V)
        {
            if(deg[it]==1) S.erase(it);
            deg[leaf]++; deg[it]++;
        }
    }
}

static void makeTree(int A[], int B[])
{
    int i, j;

    for(i=0; i<M; i++)
    {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    for(i=0; i<N; i++) sort(adj[i].begin(), adj[i].end());

    memset(num, -1, sizeof(num));
    dfs1(0);
    for(i=0; i<N; i++) if(deg[i]==1) S.insert(i);
    dfs2(0);
}

void Joi(int n, int m, int A[], int B[], ll X, int T)
{
    int i, j;
    N=n; M=m;
    makeTree(A, B);

    for(i=0; i<N; i++)
    {
        if((1ll<<col[i])&X) MessageBoard(i, 1);
        else MessageBoard(i, 0);
    }
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e4;

static int N, M, P;
static vector<int> adj[MAXN+10], tree[MAXN+10];
static int num[MAXN+10], cnt=0;
static int par[MAXN+10], deg[MAXN+10], col[MAXN+10];
static bool live[MAXN+10], togo[MAXN+10];
static ll ans;

static void dfs1(int now)
{
    num[now]=cnt++;
    if(num[now]<60)
    {
        live[now]=true;
        col[now]=num[now];
    }

    for(int nxt : adj[now])
    {
        if(num[nxt]!=-1) continue;
        dfs1(nxt);

        if(num[now]<60 && num[nxt]<60) deg[now]++, deg[nxt]++;
        tree[now].push_back(nxt);
        tree[nxt].push_back(now);
        par[nxt]=now;
    }
}

static bool vis[MAXN+10];
static set<int> S;
static void dfs2(int now)
{
    int i, j;
    vis[now]=true;

    int leaf;
    vector<int> V;
    if(num[now]>=60)
    {
        for(auto it : S) if(it!=par[now]) { leaf=it; break; }
        S.erase(leaf);
        live[leaf]=false; col[now]=col[leaf];
        for(int nxt : tree[leaf])
        {
            if(!live[nxt]) continue;
            V.push_back(nxt);
            deg[leaf]--;
            deg[nxt]--;
            if(deg[nxt]==1) S.insert(nxt);
        }

        live[now]=true;
        deg[par[now]]++;
        deg[now]++;
        S.insert(now);
    }

    if(now==P)
    {
        for(i=0; i<N; i++) togo[i]=live[i];
    }

    //printf("%d : ", now); for(i=0; i<N; i++) printf("%d ", live[i]); printf("\n");

    for(int nxt : tree[now])
    {
        if(vis[nxt]) continue;
        dfs2(nxt);
    }

    if(num[now]>=60)
    {
        deg[par[now]]--;
        deg[now]--;
        S.erase(now);
        S.insert(leaf);
        live[leaf]=true;
        live[now]=false;
        for(int it : V)
        {
            if(deg[it]==1) S.erase(it);
            deg[leaf]++; deg[it]++;
        }
    }
}

static void makeTree(int A[], int B[])
{
    int i, j;

    for(i=0; i<M; i++)
    {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    for(i=0; i<N; i++) sort(adj[i].begin(), adj[i].end());

    memset(num, -1, sizeof(num));
    dfs1(0);
    for(i=0; i<N; i++) if(deg[i]==1) S.insert(i);
    dfs2(0);
}

static void dfs3(int now)
{
    togo[now]=false;
    for(int nxt : tree[now])
    {
        if(!togo[nxt]) continue;
        ans|=(ll)Move(nxt)<<col[nxt];
        dfs3(nxt);
        ans|=(ll)Move(now)<<col[now];
    }
}

ll Ioi(int n, int m, int A[], int B[], int p, int V, int T)
{
    N=n; M=m; P=p;
    makeTree(A, B);
    int i, j;
    //for(i=0; i<N; i++) printf("%d : %d\n", i, togo[i]);
    ans|=(ll)V<<col[P];
    dfs3(P);
    return ans;
}

Compilation message

Joi.cpp: In function 'void makeTree(int*, int*)':
Joi.cpp:89:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Joi.cpp: In function 'void Joi(int, int, int*, int*, ll, int)':
Joi.cpp:106:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^

Ioi.cpp: In function 'void dfs2(int)':
Ioi.cpp:43:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Ioi.cpp: In function 'void makeTree(int*, int*)':
Ioi.cpp:99:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Ioi.cpp: In function 'll Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:130:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
Ioi.cpp:130:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1780 KB Output is correct
2 Correct 6 ms 1968 KB Output is correct
3 Incorrect 6 ms 2052 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 6792 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1908 KB Output is correct
2 Correct 5 ms 1916 KB Output is correct
3 Correct 5 ms 1780 KB Output is correct
4 Correct 9 ms 2788 KB Output is correct
5 Correct 9 ms 2768 KB Output is correct
6 Correct 9 ms 2820 KB Output is correct
7 Correct 8 ms 2656 KB Output is correct
8 Correct 9 ms 2780 KB Output is correct
9 Correct 26 ms 6808 KB Output is correct
10 Correct 27 ms 6816 KB Output is correct
11 Correct 26 ms 6828 KB Output is correct
12 Correct 6 ms 1964 KB Output is correct
13 Correct 6 ms 1792 KB Output is correct
14 Correct 6 ms 1908 KB Output is correct
15 Correct 6 ms 1836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 6672 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 6620 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -