답안 #93263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93263 2019-01-07T11:25:55 Z Alexa2001 Amusement Park (JOI17_amusement_park) C++17
0 / 100
33 ms 7244 KB
#include "Joi.h"
#include <bits/stdc++.h>

typedef long long ll;
const int Nmax = 10005;
using namespace std;

static bool used[Nmax];
static vector<int> v[Nmax];
static int bit, w[Nmax];
static ll TO;

static void dfs_sel_edges(int node)
{
    used[node] = 1;
    w[node] = 1;

    vector<int> good;
    for(auto it : v[node])
        if(!used[it]) good.push_back(it), used[it] = 1;
    v[node] = good;

    for(auto it : v[node])
    {
        dfs_sel_edges(it);
        w[node] += w[it];
    }
}

static void dfs(int node)
{
    MessageBoard(node, (TO >> bit) & 1);
    for(auto it : v[node])
        {
            bit = (bit+1) % 60;
            dfs(it);
        }
}

static bool cmp(int a, int b)
{
    return w[a] < w[b];
}

void Joi(int N, int M, int A[], int B[], ll X, int _T)
{
    int i; TO = X;
    for(i=0; i<M; ++i)
    {
        v[A[i]].push_back(B[i]);
        v[B[i]].push_back(A[i]);
    }

    dfs_sel_edges(0);

    for(i=0; i<N; ++i)
        sort(v[i].begin(), v[i].end(), cmp);

    bit = 0;
    dfs(0);
}
#include "Ioi.h"
#include <bits/stdc++.h>

typedef long long ll;
const int Nmax = 10005;
const ll AllBits = (1LL << 60) - 1;
using namespace std;

static bool used[Nmax], to_visit[Nmax];
static vector<int> v[Nmax];
static int bit, w[Nmax], t[Nmax], In[Nmax], ord[Nmax], tip[Nmax], tmp, Special;

ll Act, Mask;

static void dfs_sel_edges(int node)
{
    used[node] = 1;
    w[node] = 1;

    vector<int> good;
    for(auto it : v[node])
        if(!used[it]) good.push_back(it);
    v[node] = good;

    for(auto it : v[node])
    {
        t[it] = node;
        dfs_sel_edges(it);
        w[node] += w[it];
    }
}

static void dfs(int node)
{
    tip[node] = bit;
    In[node] = ++tmp;
    ord[tmp] = node;

    for(auto it : v[node])
        {
            bit = (bit+1) % 60;
            dfs(it);
            ord[++tmp] = node;
        }
}

bool cmp(int a, int b)
{
    return w[a] < w[b];
}

static void go(int node)
{
    to_visit[node] = 0;
    for(auto it : v[node])
        if(to_visit[it])
        {
            Act |= (1LL<<tip[it]) * Move(it);
            go(it);
            Move(node);
        }

    if(to_visit[t[node]])
    {
        Act |= (1LL<<tip[t[node]]) * Move(t[node]);
        go(t[node]);
    }
}

static ll baga(int node)
{
    int i;
    for(i=In[node]; (!to_visit[Special] || Mask != AllBits) && i <= tmp; ++i)
        to_visit[ord[i]] = 1, Mask |= (1LL << tip[ord[i]]);

    assert(to_visit[Special] && Mask == AllBits);

    go(Special);
    return Act;
}

ll Ioi(int N, int M, int A[], int B[], int P, int V, int _T)
{
    Special = P;

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

    dfs_sel_edges(0);

    for(i=0; i<N; ++i)
        sort(v[i].begin(), v[i].end(), cmp);

    bit = 0;
    dfs(0);

    int node = P, sbrb;
    while(w[node] < 60) sbrb = node, node = t[node];

    Mask = (1LL << tip[P]);
    Act = V * (1LL << tip[P]);

    if(node == P)
        return baga(P);

    vector<int> S;
    bool ok = 0; int T = 0;

    for(i=0; i<v[node].size(); ++i)
        if(v[node][i] == sbrb) ok = 1;
            else if(!ok) S.push_back(w[v[node][i]]);
                else T += w[v[node][i]];

    for(i=(int)S.size()-2; i>=0; --i) S[i] += S[i+1];

    for(i=0; i<S.size(); ++i)
        if(S[i] + w[sbrb] <= 60 && S[i] + w[sbrb] + T >= 60)
            return baga(v[node][i]);

    assert(T == 0);

    for(i=S.size()-1; i>=0; --i)
        if(S[i] + w[sbrb] >= 60) baga(v[node][i]);

    return baga(node);
}

Compilation message

Ioi.cpp: In function 'll Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:113:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<v[node].size(); ++i)
              ~^~~~~~~~~~~~~~~
Ioi.cpp:120:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<S.size(); ++i)
              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1364 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 7060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1264 KB Output is correct
2 Correct 4 ms 1524 KB Output is correct
3 Correct 4 ms 1264 KB Output is correct
4 Correct 6 ms 1940 KB Output is correct
5 Correct 6 ms 1940 KB Output is correct
6 Correct 6 ms 2000 KB Output is correct
7 Correct 6 ms 1940 KB Output is correct
8 Correct 6 ms 2120 KB Output is correct
9 Incorrect 16 ms 5856 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 7244 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 7184 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -