Submission #228058

# Submission time Handle Problem Language Result Execution time Memory
228058 2020-04-29T18:17:51 Z qkxwsm Amusement Park (JOI17_amusement_park) C++14
10 / 100
37 ms 4104 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 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);
    }
}

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
    {

    }
}
#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;
static vi edge[MAXN];
static int dsu[MAXN];
static int depth[MAXN], parent[MAXN];
static ll ans;

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);
    }
}

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));
                }
            }
        }
    }
    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 Incorrect 10 ms 1544 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3984 KB Output is correct
2 Correct 36 ms 3992 KB Output is correct
3 Correct 35 ms 3888 KB Output is correct
4 Incorrect 16 ms 2560 KB Wrong Answer [4]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1280 KB Output is correct
2 Correct 10 ms 1380 KB Output is correct
3 Correct 10 ms 1536 KB Output is correct
4 Correct 12 ms 1760 KB Output is correct
5 Correct 11 ms 2000 KB Output is correct
6 Correct 12 ms 1732 KB Output is correct
7 Correct 11 ms 1764 KB Output is correct
8 Correct 11 ms 1768 KB Output is correct
9 Correct 20 ms 4068 KB Output is correct
10 Correct 22 ms 4092 KB Output is correct
11 Correct 23 ms 4104 KB Output is correct
12 Correct 9 ms 1512 KB Output is correct
13 Correct 9 ms 1512 KB Output is correct
14 Correct 10 ms 1540 KB Output is correct
15 Correct 9 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3868 KB Output is correct
2 Correct 35 ms 3884 KB Output is correct
3 Correct 36 ms 3888 KB Output is correct
4 Incorrect 17 ms 2560 KB Wrong Answer [4]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 3884 KB Output is correct
2 Correct 37 ms 3892 KB Output is correct
3 Correct 37 ms 3892 KB Output is correct
4 Incorrect 14 ms 2560 KB Wrong Answer [4]
5 Halted 0 ms 0 KB -