Submission #228062

# Submission time Handle Problem Language Result Execution time Memory
228062 2020-04-29T18:59:48 Z qkxwsm Amusement Park (JOI17_amusement_park) C++14
81 / 100
43 ms 4132 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

static const int MAXN = 10013;

static int N, R, V = -1;
static bool islong;
static vi edge[MAXN];
static int dsu[MAXN];
static int depth[MAXN], parent[MAXN];
static vi ord;

static int get(int u)
{
    return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
    u = get(u);
    v = get(v);
    if (u == v)
    {
        return false;
    }
    dsu[u] = v;
    return true;
}
static void dfs(int u, int p)
{
    for (int v : edge[u])
    {
        if (v == p) continue;
        depth[v] = depth[u] + 1;
        parent[v] = u;
        dfs(v, u);
    }
}
static void dfs1(int u, int p)
{
    ord.PB(u);
    for (int v : edge[u])
    {
        if (v == p) continue;
        dfs1(v, u);
    }
}

void Joi(int n, int m, int e1[], int e2[], ll val, int subtask)
{
    N = n;
    iota(dsu, dsu + N, 0);
    FOR(i, 0, m)
    {
        int u = e1[i], v = e2[i];
        if (merge(u, v))
        {
            edge[u].PB(v);
            edge[v].PB(u);
            // cerr << "edge " << u << ' ' << v << endl;
        }
    }
    // cerr << "ALIVE\n";
    depth[0] = 0;
    dfs(0, N);
    FOR(i, 0, N)
    {
        if (depth[i] > depth[R])
        {
            R = i;
        }
    }
    depth[R] = 0;
    dfs(R, N);
    FOR(i, 0, N)
    {
        if (depth[i] == 59)
        {
            V = i;
        }
    }
    if (V != -1)
    {
        //solve it...
        FOR(i, 0, N)
        {
            bool b = (val & (1ll << (depth[i] % 60)));
            MessageBoard(i, b);
        }
    }
    else
    {
        dfs1(R, N);
        FOR(i, 0, N)
        {
            bool b = (val & (1ll << (i % 60)));
            MessageBoard(ord[i], b);
        }
    }
}
#include "Ioi.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

static const int MAXN = 10013;

static int N, R, V = -1;
static vi edge[MAXN];
static int dsu[MAXN];
static int depth[MAXN], parent[MAXN], pos[MAXN];
static ll ans;
static vi ord;
static ll solved = 0;

static int get(int u)
{
    return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
    u = get(u);
    v = get(v);
    if (u == v)
    {
        return false;
    }
    dsu[u] = v;
    return true;
}
//fidn the diameter o the tree. if it's >= 60, gg.
//otherwise, go to the root, and then just like take the first 60 in preorder.
static void dfs(int u, int p)
{
    for (int v : edge[u])
    {
        if (v == p) continue;
        depth[v] = depth[u] + 1;
        parent[v] = u;
        dfs(v, u);
    }
}
static void dfs1(int u, int p)
{
    pos[u] = SZ(ord);
    ord.PB(u);
    for (int v : edge[u])
    {
        if (v == p) continue;
        dfs1(v, u);
    }
}
static void dfs2(int u, int p)
{
    for (int v : edge[u])
    {
        if (v == p) continue;
        // cerr << "Moving " << u << " -> " << v << endl;
        int va = Move(v);
        if (va)
        {
            ans |= (1ll << (pos[v] % 60));
        }
        solved |= (1ll << (pos[v] % 60));
        if (solved == (1ll << 60) - 1)
        {
            return;
        }
        dfs2(v, u);
        if (solved == (1ll << 60) - 1)
        {
            return;
        }
        // cerr << "Moving " << v << " -> " << u << endl;
        Move(u);
    }
}

ll Ioi(int n, int m, int e1[], int e2[], int st, int va, int subtask)
{
    N = n;
    iota(dsu, dsu + N, 0);
    FOR(i, 0, m)
    {
        int u = e1[i], v = e2[i];
        if (merge(u, v))
        {
            edge[u].PB(v);
            edge[v].PB(u);
            // cerr << "edge " << u << ' ' << v << endl;
        }
    }
    depth[0] = 0;
    dfs(0, N);
    FOR(i, 0, N)
    {
        if (depth[i] > depth[R])
        {
            R = i;
        }
    }
    depth[R] = 0;
    dfs(R, N);
    FOR(i, 0, N)
    {
        if (depth[i] == 59)
        {
            V = i;
        }
    }
    // cerr << "R = " << R << " V = " << V << endl;
    if (V != -1)
    {
        vi path; path.PB(V);
        while(path.back() != R)
        {
            path.PB(parent[path.back()]);
        }
        reverse(ALL(path));
        if (depth[st] >= 59)
        {
            if (va)
            {
                ans += (1ll << (depth[st] % 60));
            }
            FOR(i, 0, 59)
            {
                va = Move(parent[st]);
                st = parent[st];
                if (va)
                {
                    ans += (1ll << (depth[st] % 60));
                }
            }
        }
        else
        {
            while(st != R)
            {
                va = Move(parent[st]);
                st = parent[st];
            }
            if (va)
            {
                ans += (1ll << (depth[st] % 60));
            }
            FOR(i, 1, 60)
            {
                va = Move(path[i]);
                st = path[i];
                if (va)
                {
                    ans += (1ll << (depth[st] % 60));
                }
            }
        }
    }
    else
    {
        dfs1(R, N);
        if (va)
        {
            ans |= (1ll << (pos[st] % 60));
        }
        solved |= (1ll << (pos[st] % 60));
        // cerr << "st = " << st << endl;
        while(st != R)
        {
            va = Move(parent[st]);
            // cerr << "move " << parent[st] << endl;
            st = parent[st];
            if (va)
            {
                ans |= (1ll << (pos[st] % 60));
            }
            solved |= (1ll << (pos[st] % 60));
        }
        dfs2(R, N);
    }
    return ans;
}

Compilation message

Joi.cpp:41:13: warning: 'islong' defined but not used [-Wunused-variable]
 static bool islong;
             ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1292 KB Output is correct
2 Correct 10 ms 1264 KB Output is correct
3 Correct 10 ms 1304 KB Output is correct
4 Correct 10 ms 1528 KB Output is correct
5 Correct 11 ms 1576 KB Output is correct
6 Correct 10 ms 1536 KB Output is correct
7 Correct 10 ms 1528 KB Output is correct
8 Correct 11 ms 1512 KB Output is correct
9 Correct 10 ms 1680 KB Output is correct
10 Correct 10 ms 1416 KB Output is correct
11 Correct 13 ms 1724 KB Output is correct
12 Correct 10 ms 1524 KB Output is correct
13 Correct 10 ms 1524 KB Output is correct
14 Correct 10 ms 1432 KB Output is correct
15 Correct 10 ms 1528 KB Output is correct
16 Correct 10 ms 1532 KB Output is correct
17 Correct 10 ms 1504 KB Output is correct
18 Correct 10 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3476 KB Output is correct
2 Correct 35 ms 3692 KB Output is correct
3 Correct 35 ms 3484 KB Output is correct
4 Correct 27 ms 3164 KB Output is correct
5 Correct 25 ms 4132 KB Output is correct
6 Correct 25 ms 3372 KB Output is correct
7 Correct 25 ms 3596 KB Output is correct
8 Correct 26 ms 3820 KB Output is correct
9 Correct 26 ms 3592 KB Output is correct
10 Correct 25 ms 3592 KB Output is correct
11 Correct 25 ms 3620 KB Output is correct
12 Correct 24 ms 3348 KB Output is correct
13 Correct 26 ms 3368 KB Output is correct
14 Correct 25 ms 3312 KB Output is correct
15 Correct 26 ms 3416 KB Output is correct
16 Correct 26 ms 3412 KB Output is correct
17 Correct 26 ms 3408 KB Output is correct
18 Correct 27 ms 3408 KB Output is correct
19 Correct 25 ms 3420 KB Output is correct
20 Correct 22 ms 3500 KB Output is correct
21 Correct 23 ms 3560 KB Output is correct
22 Correct 26 ms 3528 KB Output is correct
23 Correct 25 ms 3556 KB Output is correct
24 Correct 26 ms 3548 KB Output is correct
25 Correct 25 ms 3528 KB Output is correct
26 Correct 25 ms 3552 KB Output is correct
27 Correct 27 ms 3548 KB Output is correct
28 Correct 25 ms 3564 KB Output is correct
29 Correct 25 ms 3348 KB Output is correct
30 Correct 25 ms 3588 KB Output is correct
31 Correct 10 ms 1532 KB Output is correct
32 Correct 10 ms 1524 KB Output is correct
33 Correct 10 ms 1520 KB Output is correct
34 Correct 10 ms 1416 KB Output is correct
35 Correct 10 ms 1536 KB Output is correct
36 Correct 10 ms 1532 KB Output is correct
37 Correct 9 ms 1536 KB Output is correct
38 Correct 10 ms 1536 KB Output is correct
39 Correct 10 ms 1416 KB Output is correct
40 Correct 10 ms 1536 KB Output is correct
41 Correct 10 ms 1536 KB Output is correct
42 Correct 10 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1284 KB Output is correct
2 Correct 9 ms 1540 KB Output is correct
3 Correct 10 ms 1412 KB Output is correct
4 Correct 12 ms 1700 KB Output is correct
5 Correct 11 ms 1764 KB Output is correct
6 Correct 11 ms 1732 KB Output is correct
7 Correct 11 ms 1752 KB Output is correct
8 Correct 11 ms 1760 KB Output is correct
9 Correct 20 ms 3848 KB Output is correct
10 Correct 20 ms 3848 KB Output is correct
11 Correct 20 ms 3848 KB Output is correct
12 Correct 10 ms 1284 KB Output is correct
13 Correct 10 ms 1284 KB Output is correct
14 Correct 9 ms 1520 KB Output is correct
15 Correct 10 ms 1544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3476 KB Output is correct
2 Correct 36 ms 3588 KB Output is correct
3 Correct 35 ms 3428 KB Output is correct
4 Partially correct 25 ms 3152 KB Partially correct
5 Correct 25 ms 4112 KB Output is correct
6 Correct 25 ms 3600 KB Output is correct
7 Correct 26 ms 3648 KB Output is correct
8 Correct 27 ms 3832 KB Output is correct
9 Correct 25 ms 3592 KB Output is correct
10 Correct 24 ms 3484 KB Output is correct
11 Correct 23 ms 3520 KB Output is correct
12 Correct 23 ms 3372 KB Output is correct
13 Partially correct 27 ms 3348 KB Partially correct
14 Partially correct 24 ms 3316 KB Partially correct
15 Partially correct 26 ms 3268 KB Partially correct
16 Partially correct 25 ms 3260 KB Partially correct
17 Correct 28 ms 3408 KB Output is correct
18 Partially correct 25 ms 3412 KB Partially correct
19 Partially correct 26 ms 3424 KB Partially correct
20 Correct 22 ms 3516 KB Output is correct
21 Correct 20 ms 3516 KB Output is correct
22 Correct 25 ms 3552 KB Output is correct
23 Correct 27 ms 3732 KB Output is correct
24 Correct 26 ms 3548 KB Output is correct
25 Correct 26 ms 3536 KB Output is correct
26 Correct 26 ms 3560 KB Output is correct
27 Correct 26 ms 3548 KB Output is correct
28 Correct 24 ms 3544 KB Output is correct
29 Correct 23 ms 3600 KB Output is correct
30 Correct 24 ms 3592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3620 KB Output is correct
2 Correct 35 ms 3556 KB Output is correct
3 Correct 35 ms 3632 KB Output is correct
4 Incorrect 26 ms 3160 KB Output isn't correct
5 Halted 0 ms 0 KB -