Submission #143787

# Submission time Handle Problem Language Result Execution time Memory
143787 2019-08-15T05:38:57 Z jwvg0425 Split the Attractions (IOI19_split) C++17
0 / 100
1126 ms 1048580 KB
#include "split.h"
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

vector<int> edge[100005];
int sub[100005];
int parent[100005];
int check[100005];

void dfs(int root)
{
    sub[root] = 1;
    for (auto&e : edge[root])
    {
        if (e == parent[root])
            continue;

        parent[e] = root;
        dfs(e);
        sub[root] += sub[e];
    }
}

void mark(int root, vector<int>& num, int& a, int& b)
{
    for (auto& e : edge[root])
    {
        if (e == parent[root])
            continue;

        if (check[e] == 0)
            check[e] = check[root];
    }

    if (check[root] == 1 && a > 0)
    {
        num[root] = 1;
        a--;
    }

    if (check[root] == 2 && b > 0)
    {
        num[root] = 2;
        b--;
    }

    for (auto& e : edge[root])
    {
        if (e == parent[root])
            continue;

        mark(e, num, a, b);
    }
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
    memset(parent, -1, sizeof(parent));
    for (int i = 0; i < p.size(); i++)
    {
        edge[p[i]].push_back(q[i]);
        edge[q[i]].push_back(p[i]);
    }

    vector<int> num(n, 0);

    dfs(0);

    for (int i = 1; i < n; i++)
    {
        int ai = sub[i];
        int bi = n - sub[i];

        if (min(ai, bi) < min(a, b) || max(ai, bi) < max(a, b))
            continue;

        if (ai >= a && bi < a)
        {
            check[i] = 1;
            check[0] = 2;
        }
        else
        {
            check[0] = 1;
            check[i] = 2;
        }
        
        mark(0, num, a, b);

        for (int j = 0; j < n; j++)
        {
            if (num[j] == 0)
                num[j] = 3;
        }

        break;
    }

    return num;
}

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:82:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < p.size(); i++)
                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB ok, correct split
2 Runtime error 1079 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3064 KB ok, correct split
2 Runtime error 1126 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3192 KB ok, correct split
2 Correct 95 ms 9080 KB ok, correct split
3 Incorrect 34 ms 5496 KB invalid split: #1=33, #2=37, #3=40030
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1035 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB ok, correct split
2 Runtime error 1079 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -