Submission #128100

# Submission time Handle Problem Language Result Execution time Memory
128100 2019-07-10T12:22:03 Z arnold518 Amusement Park (JOI17_amusement_park) C++14
18 / 100
3000 ms 11584 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 bool element(int grp, int x)
{
    int i, j;
    for(int it : group[grp]) if(it==x) return true;
    return false;
}

static int leaf;
static void dfs(int now, int bef, int grp)
{
    if(cnt==60) { leaf=now; return; }
    cnt++;
    for(int nxt : tree[now])
    {
        if(nxt==bef) continue;
        if(!element(grp, 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);
    }
}

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 bool element(int grp, int x)
{
    int i, j;
    for(int it : group[grp]) if(it==x) return true;
    return false;
}

static int leaf;
static void dfs(int now, int bef, int grp)
{
    if(cnt==60) { leaf=now; return; }
    cnt++;
    for(int nxt : tree[now])
    {
        if(nxt==bef) continue;
        if(!element(grp, 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(!element(P, 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 'bool element(int, int)':
Joi.cpp:41:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
Joi.cpp:41:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Joi.cpp: In function 'void color()':
Joi.cpp:61:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Joi.cpp: In function 'void Joi(int, int, int*, int*, ll, int)':
Joi.cpp:79: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 'bool element(int, int)':
Ioi.cpp:41:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
Ioi.cpp:41:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
Ioi.cpp: In function 'void color()':
Ioi.cpp:61: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:92:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2288 KB Output is correct
2 Correct 6 ms 2484 KB Output is correct
3 Correct 8 ms 2680 KB Output is correct
4 Correct 6 ms 2416 KB Output is correct
5 Correct 6 ms 2456 KB Output is correct
6 Correct 6 ms 2552 KB Output is correct
7 Correct 8 ms 2628 KB Output is correct
8 Correct 11 ms 2772 KB Output is correct
9 Correct 8 ms 2776 KB Output is correct
10 Correct 6 ms 2468 KB Output is correct
11 Correct 9 ms 2468 KB Output is correct
12 Correct 4 ms 2288 KB Output is correct
13 Correct 8 ms 2552 KB Output is correct
14 Correct 8 ms 2564 KB Output is correct
15 Correct 8 ms 2560 KB Output is correct
16 Correct 8 ms 2680 KB Output is correct
17 Correct 8 ms 2688 KB Output is correct
18 Correct 8 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 11340 KB Output is correct
2 Correct 134 ms 11436 KB Output is correct
3 Correct 135 ms 11320 KB Output is correct
4 Correct 181 ms 9996 KB Output is correct
5 Correct 103 ms 10744 KB Output is correct
6 Correct 162 ms 10680 KB Output is correct
7 Correct 173 ms 10308 KB Output is correct
8 Correct 178 ms 10304 KB Output is correct
9 Correct 155 ms 10580 KB Output is correct
10 Execution timed out 3017 ms 4224 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2544 KB Output is correct
2 Correct 6 ms 2552 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 17 ms 3768 KB Output is correct
5 Correct 17 ms 3756 KB Output is correct
6 Correct 16 ms 3740 KB Output is correct
7 Correct 16 ms 3600 KB Output is correct
8 Correct 17 ms 3740 KB Output is correct
9 Correct 79 ms 11172 KB Output is correct
10 Correct 80 ms 10940 KB Output is correct
11 Correct 79 ms 10936 KB Output is correct
12 Correct 6 ms 2424 KB Output is correct
13 Correct 6 ms 2436 KB Output is correct
14 Correct 6 ms 2472 KB Output is correct
15 Correct 5 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 11584 KB Output is correct
2 Correct 137 ms 11416 KB Output is correct
3 Correct 137 ms 11320 KB Output is correct
4 Correct 149 ms 10032 KB Output is correct
5 Correct 104 ms 10560 KB Output is correct
6 Correct 166 ms 10300 KB Output is correct
7 Correct 169 ms 10244 KB Output is correct
8 Correct 176 ms 10468 KB Output is correct
9 Correct 174 ms 10496 KB Output is correct
10 Execution timed out 3037 ms 4300 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 137 ms 11348 KB Output is correct
2 Correct 136 ms 11436 KB Output is correct
3 Correct 137 ms 11368 KB Output is correct
4 Correct 159 ms 9884 KB Output is correct
5 Correct 106 ms 11076 KB Output is correct
6 Correct 173 ms 10392 KB Output is correct
7 Correct 175 ms 10492 KB Output is correct
8 Correct 166 ms 10436 KB Output is correct
9 Correct 167 ms 10476 KB Output is correct
10 Execution timed out 3015 ms 4412 KB Time limit exceeded
11 Halted 0 ms 0 KB -