Submission #128086

# Submission time Handle Problem Language Result Execution time Memory
128086 2019-07-10T12:02:48 Z arnold518 Amusement Park (JOI17_amusement_park) C++14
18 / 100
3000 ms 11788 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 ll X;

static vector<int> adj[MAXN+10], tree[MAXN+10], group[MAXN+10];
static int dis[MAXN+10], invdis[MAXN+10], par[MAXN+10], col[MAXN+10];

static int cnt=0;
static void makeTree(int now)
{
    int i, j;
    dis[now]=cnt++;
    invdis[dis[now]]=now;
    if(dis[now]<60)
    {
        group[now].push_back(now);
        col[now]=dis[now];
    }

    for(int nxt : adj[now])
    {
        if(dis[nxt]!=-1) continue;
        makeTree(nxt);
        tree[now].push_back(nxt);
        tree[nxt].push_back(now);
        par[nxt]=now;
    }
}

static int leaf;
static void dfs(int now, int bef, int grp)
{
    if(cnt==60) leaf=now;
    cnt++;
    for(int nxt : tree[now])
    {
        if(nxt==bef) continue;
        if(!binary_search(group[grp].begin(), group[grp].end(), nxt)) continue;
        dfs(nxt, now, grp);
    }
}

static void color()
{
    int i, j;
    vector<int> start;
    for(i=0; i<N; i++) if(dis[i]<60) start.push_back(group[i][0]);
    for(i=0; i<N; i++) if(dis[i]<60) group[i]=start;

    for(i=60; i<N; i++)
    {
        int now=invdis[i];
        cnt=1; leaf=0;
        dfs(par[now], now, par[now]);
        for(int it : group[par[now]]) if(it!=leaf) group[now].push_back(it);
        col[now]=col[leaf];
        group[now].push_back(now);
        sort(group[now].begin(), group[now].end());
    }
}

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

    for(i=0; i<M; i++)
    {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }

    memset(dis, -1, sizeof(dis));
    memset(col, -1, sizeof(col));
    makeTree(1);
    color();

    for(i=0; i<N; i++)
    {
        if(x&(1ll<<col[i])) 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, V;

static vector<int> adj[MAXN+10], tree[MAXN+10], group[MAXN+10];
static int dis[MAXN+10], invdis[MAXN+10], par[MAXN+10], col[MAXN+10];
static ll ans;

static int cnt=0;
static void makeTree(int now)
{
    int i, j;
    dis[now]=cnt++;
    invdis[dis[now]]=now;
    if(dis[now]<60)
    {
        group[now].push_back(now);
        col[now]=dis[now];
    }

    for(int nxt : adj[now])
    {
        if(dis[nxt]!=-1) continue;
        makeTree(nxt);
        tree[now].push_back(nxt);
        tree[nxt].push_back(now);
        par[nxt]=now;
    }
}

static int leaf;
static void dfs(int now, int bef, int grp)
{
    if(cnt==60) leaf=now;
    cnt++;
    for(int nxt : tree[now])
    {
        if(nxt==bef) continue;
        if(!binary_search(group[grp].begin(), group[grp].end(), nxt)) continue;
        dfs(nxt, now, grp);
    }
}

static void color()
{
    int i, j;
    vector<int> start;
    for(i=0; i<N; i++) if(dis[i]<60) start.push_back(group[i][0]);
    for(i=0; i<N; i++) if(dis[i]<60) group[i]=start;

    for(i=60; i<N; i++)
    {
        int now=invdis[i];
        cnt=1; leaf=0;
        dfs(par[now], now, par[now]);
        for(int it : group[par[now]]) if(it!=leaf) group[now].push_back(it);
        col[now]=col[leaf];
        group[now].push_back(now);
        sort(group[now].begin(), group[now].end());
    }
}

static void tour(int now, int bef)
{
    for(int nxt : tree[now])
    {
        if(nxt==bef) continue;
        if(!binary_search(group[P].begin(), group[P].end(), nxt)) continue;
        ans|=(ll)Move(nxt)<<col[nxt];
        tour(nxt, now);
        ans|=(ll)Move(now)<<col[now];
    }
}

ll Ioi(int n, int m, int A[], int B[], int p, int v, int T)
{
    int i, j;
    N=n; M=m; P=p; V=v;

    for(i=0; i<M; i++)
    {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }

    memset(dis, -1, sizeof(dis));
    memset(col, -1, sizeof(col));
    makeTree(1);
    color();

    ans|=(ll)V<<col[P];
    tour(P, P);
    return ans;
}

Compilation message

Joi.cpp: In function 'void makeTree(int)':
Joi.cpp:20:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
Joi.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Joi.cpp: In function 'void color()':
Joi.cpp:54:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Joi.cpp: In function 'void Joi(int, int, int*, int*, ll, int)':
Joi.cpp:73:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^

Ioi.cpp: In function 'void makeTree(int)':
Ioi.cpp:20:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
Ioi.cpp:20:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Ioi.cpp: In function 'void color()':
Ioi.cpp:54: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:85:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2464 KB Output is correct
2 Correct 6 ms 2428 KB Output is correct
3 Correct 8 ms 2692 KB Output is correct
4 Correct 6 ms 2428 KB Output is correct
5 Correct 6 ms 2428 KB Output is correct
6 Correct 7 ms 2456 KB Output is correct
7 Correct 8 ms 2696 KB Output is correct
8 Correct 8 ms 2788 KB Output is correct
9 Correct 8 ms 2820 KB Output is correct
10 Correct 6 ms 2568 KB Output is correct
11 Correct 10 ms 2888 KB Output is correct
12 Correct 6 ms 2468 KB Output is correct
13 Correct 8 ms 2684 KB Output is correct
14 Correct 8 ms 2688 KB Output is correct
15 Correct 8 ms 2636 KB Output is correct
16 Correct 8 ms 2640 KB Output is correct
17 Correct 8 ms 2684 KB Output is correct
18 Correct 8 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 11492 KB Output is correct
2 Correct 141 ms 11784 KB Output is correct
3 Correct 138 ms 11652 KB Output is correct
4 Correct 153 ms 10252 KB Output is correct
5 Correct 117 ms 10940 KB Output is correct
6 Correct 158 ms 10748 KB Output is correct
7 Correct 162 ms 10432 KB Output is correct
8 Correct 162 ms 10520 KB Output is correct
9 Correct 149 ms 10648 KB Output is correct
10 Execution timed out 3035 ms 4824 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2292 KB Output is correct
2 Correct 6 ms 2428 KB Output is correct
3 Correct 6 ms 2548 KB Output is correct
4 Correct 14 ms 3616 KB Output is correct
5 Correct 15 ms 3616 KB Output is correct
6 Correct 15 ms 4000 KB Output is correct
7 Correct 15 ms 3996 KB Output is correct
8 Correct 15 ms 3880 KB Output is correct
9 Correct 65 ms 11288 KB Output is correct
10 Correct 65 ms 11284 KB Output is correct
11 Correct 64 ms 11160 KB Output is correct
12 Correct 5 ms 2468 KB Output is correct
13 Correct 6 ms 2296 KB Output is correct
14 Correct 6 ms 2472 KB Output is correct
15 Correct 6 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 11752 KB Output is correct
2 Correct 141 ms 11788 KB Output is correct
3 Correct 140 ms 11700 KB Output is correct
4 Correct 135 ms 10200 KB Output is correct
5 Correct 119 ms 10904 KB Output is correct
6 Correct 157 ms 10648 KB Output is correct
7 Correct 153 ms 10580 KB Output is correct
8 Correct 156 ms 10588 KB Output is correct
9 Correct 155 ms 10648 KB Output is correct
10 Execution timed out 3046 ms 4544 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 138 ms 11520 KB Output is correct
2 Correct 140 ms 11524 KB Output is correct
3 Correct 140 ms 11612 KB Output is correct
4 Correct 134 ms 10148 KB Output is correct
5 Correct 117 ms 11160 KB Output is correct
6 Correct 157 ms 10536 KB Output is correct
7 Correct 150 ms 10648 KB Output is correct
8 Correct 143 ms 10740 KB Output is correct
9 Correct 152 ms 10460 KB Output is correct
10 Execution timed out 3016 ms 4480 KB Time limit exceeded
11 Halted 0 ms 0 KB -