Submission #220047

# Submission time Handle Problem Language Result Execution time Memory
220047 2020-04-06T21:08:08 Z VEGAnn Split the Attractions (IOI19_split) C++14
40 / 100
149 ms 23544 KB
#include <bits/stdc++.h>
#include "split.h"
#define all(x) x.begin(),x.end()
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 100100;
vector<int> res;
vector<int> g[N], vc, children[N];
bool mrk[N];
int A[3], C[3], mrk_col[N], h[N], mn_h[N], pr[N], siz[N], mem = 0;

void dfs(int v, int p){
    pr[v] = p;
    siz[v] = 1;
    mrk[v] = 1;
    mn_h[v] = h[v];

    for (int u : g[v]){
        if (mrk[u]) continue;
        children[v].PB(u);
        h[u] = h[v] + 1;

        dfs(u, v);

        mn_h[v] = min(mn_h[v], mn_h[u]);
        siz[v] += siz[u];
    }
}

void col(int v, int cl){
    mrk_col[v] = cl;

    for (int u : children[v])
        col(u, cl);
}

void DFS(int v, int cl, int rlc){
    if (mrk[v]) return;
    if (mem == 0) return;

    mem--;
    mrk[v] = 1;
    res[v] = rlc;

    for (int u : g[v])
        if (mrk_col[u] == cl)
            DFS(u, cl, rlc);
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	res.resize(n);
	fill(all(res), 0);

	for (int i = sz(p) - 1; i >= 0; i--){
        g[p[i]].PB(q[i]);
        g[q[i]].PB(p[i]);
	}

	A[0] = a; A[1] = b; A[2] = c;
	C[0] = 1; C[1] = 2; C[2] = 3;

	if (A[0] > A[1]) {
        swap(A[0], A[1]);
        swap(C[0], C[1]);
	}
	if (A[1] > A[2]) {
        swap(A[1], A[2]);
        swap(C[1], C[2]);
	}
	if (A[0] > A[1]) {
        swap(A[0], A[1]);
        swap(C[0], C[1]);
	}

    dfs(0, -1);

    for (int v = 0; v < n; v++){
        bool ok = bool(siz[v] >= A[0]);

        for (int u : children[v])
            ok &= bool(siz[u] < A[0]);

        if (!ok) continue;

        col(0, 1);
        col(v, 2);

        int real_siz = siz[v];

        for (int u : children[v])
            if (mn_h[u] < h[v] && real_siz - siz[u] >= A[0]){
                real_siz -= siz[u];
                col(u, 1);
            }

        for (int t1 = 0; t1 < 2; t1++){
            int t2 = 1 - t1;

            if (real_siz >= A[t1] && n - real_siz >= A[t2]){
                fill(mrk, mrk + n, 0);

                mem = A[t2];
                DFS(pr[v], 1, C[t2]);

                mem = A[t1];
                DFS(v, 2, C[t1]);

                for (int &cr : res)
                    if (cr == 0)
                        cr = C[2];

                return res;
            }
        }
    }

	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 5120 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 4992 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 133 ms 23136 KB ok, correct split
8 Correct 109 ms 20856 KB ok, correct split
9 Correct 116 ms 20216 KB ok, correct split
10 Correct 109 ms 23544 KB ok, correct split
11 Correct 119 ms 23544 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 4992 KB ok, correct split
4 Correct 126 ms 19320 KB ok, correct split
5 Correct 99 ms 14328 KB ok, correct split
6 Correct 112 ms 23544 KB ok, correct split
7 Correct 115 ms 20728 KB ok, correct split
8 Correct 149 ms 16888 KB ok, correct split
9 Correct 109 ms 15864 KB ok, correct split
10 Correct 66 ms 13424 KB ok, correct split
11 Correct 75 ms 13812 KB ok, correct split
12 Correct 65 ms 13424 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 113 ms 14328 KB ok, correct split
3 Correct 47 ms 8824 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 116 ms 18296 KB ok, correct split
6 Correct 113 ms 18040 KB ok, correct split
7 Correct 126 ms 17912 KB ok, correct split
8 Correct 116 ms 19192 KB ok, correct split
9 Correct 116 ms 17656 KB ok, correct split
10 Correct 33 ms 8064 KB ok, no valid answer
11 Correct 44 ms 9592 KB ok, no valid answer
12 Correct 79 ms 13684 KB ok, no valid answer
13 Correct 101 ms 14208 KB ok, no valid answer
14 Correct 64 ms 13424 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB ok, correct split
2 Correct 7 ms 4992 KB ok, no valid answer
3 Correct 8 ms 5248 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 4992 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 7 ms 4992 KB ok, correct split
8 Correct 7 ms 4992 KB ok, correct split
9 Correct 10 ms 5376 KB ok, correct split
10 Correct 9 ms 5376 KB ok, correct split
11 Correct 7 ms 5120 KB ok, correct split
12 Correct 10 ms 5376 KB ok, correct split
13 Correct 7 ms 4992 KB ok, correct split
14 Correct 7 ms 4992 KB ok, correct split
15 Correct 7 ms 5120 KB ok, correct split
16 Correct 8 ms 4992 KB ok, correct split
17 Correct 7 ms 4992 KB ok, correct split
18 Correct 7 ms 4992 KB ok, correct split
19 Correct 7 ms 5120 KB ok, correct split
20 Correct 8 ms 5120 KB ok, correct split
21 Correct 9 ms 5376 KB ok, correct split
22 Correct 9 ms 5376 KB ok, correct split
23 Correct 9 ms 5376 KB ok, correct split
24 Correct 9 ms 5376 KB ok, correct split
25 Correct 9 ms 5376 KB ok, correct split
26 Incorrect 9 ms 5248 KB jury found a solution, contestant did not
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 5120 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 4992 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 133 ms 23136 KB ok, correct split
8 Correct 109 ms 20856 KB ok, correct split
9 Correct 116 ms 20216 KB ok, correct split
10 Correct 109 ms 23544 KB ok, correct split
11 Correct 119 ms 23544 KB ok, correct split
12 Correct 7 ms 4992 KB ok, correct split
13 Correct 7 ms 4992 KB ok, correct split
14 Correct 7 ms 4992 KB ok, correct split
15 Correct 126 ms 19320 KB ok, correct split
16 Correct 99 ms 14328 KB ok, correct split
17 Correct 112 ms 23544 KB ok, correct split
18 Correct 115 ms 20728 KB ok, correct split
19 Correct 149 ms 16888 KB ok, correct split
20 Correct 109 ms 15864 KB ok, correct split
21 Correct 66 ms 13424 KB ok, correct split
22 Correct 75 ms 13812 KB ok, correct split
23 Correct 65 ms 13424 KB ok, correct split
24 Correct 7 ms 4992 KB ok, correct split
25 Correct 113 ms 14328 KB ok, correct split
26 Correct 47 ms 8824 KB ok, correct split
27 Correct 7 ms 4992 KB ok, correct split
28 Correct 116 ms 18296 KB ok, correct split
29 Correct 113 ms 18040 KB ok, correct split
30 Correct 126 ms 17912 KB ok, correct split
31 Correct 116 ms 19192 KB ok, correct split
32 Correct 116 ms 17656 KB ok, correct split
33 Correct 33 ms 8064 KB ok, no valid answer
34 Correct 44 ms 9592 KB ok, no valid answer
35 Correct 79 ms 13684 KB ok, no valid answer
36 Correct 101 ms 14208 KB ok, no valid answer
37 Correct 64 ms 13424 KB ok, no valid answer
38 Correct 7 ms 5120 KB ok, correct split
39 Correct 7 ms 4992 KB ok, no valid answer
40 Correct 8 ms 5248 KB ok, correct split
41 Correct 7 ms 4992 KB ok, correct split
42 Correct 7 ms 4992 KB ok, correct split
43 Correct 7 ms 4992 KB ok, correct split
44 Correct 7 ms 4992 KB ok, correct split
45 Correct 7 ms 4992 KB ok, correct split
46 Correct 10 ms 5376 KB ok, correct split
47 Correct 9 ms 5376 KB ok, correct split
48 Correct 7 ms 5120 KB ok, correct split
49 Correct 10 ms 5376 KB ok, correct split
50 Correct 7 ms 4992 KB ok, correct split
51 Correct 7 ms 4992 KB ok, correct split
52 Correct 7 ms 5120 KB ok, correct split
53 Correct 8 ms 4992 KB ok, correct split
54 Correct 7 ms 4992 KB ok, correct split
55 Correct 7 ms 4992 KB ok, correct split
56 Correct 7 ms 5120 KB ok, correct split
57 Correct 8 ms 5120 KB ok, correct split
58 Correct 9 ms 5376 KB ok, correct split
59 Correct 9 ms 5376 KB ok, correct split
60 Correct 9 ms 5376 KB ok, correct split
61 Correct 9 ms 5376 KB ok, correct split
62 Correct 9 ms 5376 KB ok, correct split
63 Incorrect 9 ms 5248 KB jury found a solution, contestant did not
64 Halted 0 ms 0 KB -