Submission #552456

# Submission time Handle Problem Language Result Execution time Memory
552456 2022-04-23T07:48:11 Z Killer2501 Amusement Park (JOI17_amusement_park) C++14
0 / 100
129 ms 126488 KB
#include "Joi.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+2;
const int M = 60;
const int mod = 1e9+7;
const ll base = 1e6;
const ll inf = 1e9;
int n, m, b[N], a[N], k, d[N], cnt, par[N], f[N];
ll ans;
vector<int> adj[N];
bool vis[N];
set<pii> leaf;
set<int> st[N];
void dfs(int u)
{

    vis[u] = true;
    if(cnt < M)d[u] = cnt++;
    else
    {
        auto it = leaf.begin();
        if(u != 0 && d[par[u]] == (*it).se)++it;
        int v = (*it).se;
        d[u] = v;
        leaf.erase(it);
        for(int x: st[v])
        {
            leaf.erase({st[x].size(), x});
            st[x].erase(v);
            leaf.insert({st[x].size(), x});
        }
        st[v].clear();
    }
    leaf.insert({0, d[u]});
    if(u != 0)
    {
        int v = d[par[u]];
        leaf.erase({st[d[u]].size(), d[u]});
        leaf.erase({st[v].size(), v});
        st[v].insert(d[u]);
        st[d[u]].insert(v);
        leaf.insert({st[d[u]].size(), d[u]});
        leaf.insert({st[v].size(), v});
    }
    //cout << u <<" "<<d[u]<<'\n';
    for(int v: adj[u])
    {
        if(vis[v])continue;
        par[v] = u;
        dfs(v);
    }
}
void Joi(int n, int m, int A[], int B[], ll x, int T)
{
    for(int i = 0; i < n; i ++)
    {
        st[i].clear();
        adj[i].clear();
    }
    leaf.clear();
    cnt = 0;
    for(int i = 0; i < m; i ++)
    {
        adj[A[i]].pb(B[i]);
        adj[B[i]].pb(A[i]);
    }
    fill_n(d, n, -1);
    fill_n(par, n, -1);
    fill_n(vis, n, 0);
    dfs(0);
    for(int i = 0; i < n; i ++)
        MessageBoard(i, (x>>d[i]&1));
}
#include "Ioi.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+2;
const int M = 60;
const int mod = 1e9+7;
const ll base = 1e6;
const ll inf = 1e9;
int n, m, b[N], a[N], k, d[N], cnt, par[N], f[N];
ll ans;
vector<int> adj[N];
bool vis[N];
set<pii> leaf;
set<int> st[N];
void dfs(int u)
{

    vis[u] = true;
    if(cnt < M)d[u] = cnt++;
    else
    {
        auto it = leaf.begin();
        if(u != 0 && d[par[u]] == (*it).se)++it;
        int v = (*it).se;
        d[u] = v;
        leaf.erase(it);
        for(int x: st[v])
        {
            leaf.erase({st[x].size(), x});
            st[x].erase(v);
            leaf.insert({st[x].size(), x});
        }
        st[v].clear();
    }
    leaf.insert({0, d[u]});
    if(u != 0)
    {
        int v = d[par[u]];
        leaf.erase({st[d[u]].size(), d[u]});
        leaf.erase({st[v].size(), v});
        st[v].insert(d[u]);
        st[d[u]].insert(v);
        leaf.insert({st[d[u]].size(), d[u]});
        leaf.insert({st[v].size(), v});
    }
    //cout << u <<" "<<d[u]<<'\n';
    for(int v: adj[u])
    {
        if(vis[v])continue;
        par[v] = u;
        dfs(v);
    }
}
int dd[1002][10002], lst;
bool save;
void cal(int u)
{
    //cout << u <<" "<<d[u]<<" "<<a[d[u]]<<'\n';
    if(save)return;
    for(int v: adj[u])
    {
        if(a[d[v]] == -1)
        {
            if(!dd[lst][v])
            {
                save = true;
                return;
            }
            else lst = v;
            a[d[v]] = Move(v);
            cal(v);
            Move(u);
            if(!dd[lst][u])
            {
                save = true;
                return;
            }
            else lst = u;
        }
    }
}
ll Ioi(int n, int m, int A[], int B[], int P, int V, int T)
{
    for(int i = 0; i < n; i ++)
    {
        st[i].clear();
        adj[i].clear();
    }
    leaf.clear();
    cnt = 0;
    memset(dd, 0, sizeof(dd));
    for(int i = 0; i < m; i ++)
    {
        adj[A[i]].pb(B[i]);
        adj[B[i]].pb(A[i]);
      	dd[A[i]][B[i]] = dd[B[i]][A[i]] = 1;
    }
    lst = P;
    fill_n(d, n, -1);
    fill_n(par, n, -1);
    fill_n(vis, n, 0);
    dfs(0);
    fill_n(a, M, -1);
    a[d[P]] = V;
    cal(P);
    ll res = 0;
    for(int i = 0; i < M; i ++)
    {
        //cout << a[i] <<" "<<i<<'\n';
        if(a[i])
            res |= (1ll<<i);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 68188 KB Output is correct
2 Correct 39 ms 68076 KB Output is correct
3 Incorrect 40 ms 68080 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 115 ms 126488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 67980 KB Output is correct
2 Correct 38 ms 68004 KB Output is correct
3 Correct 43 ms 67960 KB Output is correct
4 Runtime error 90 ms 124384 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 96 ms 126464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 129 ms 126444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -