Submission #1078308

# Submission time Handle Problem Language Result Execution time Memory
1078308 2024-08-27T15:08:07 Z c2zi6 Beech Tree (IOI23_beechtree) C++17
31 / 100
128 ms 31296 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "beechtree.h"

namespace TEST2 {
    bool check(VI par) {
        rep(i, par.size()) if (par[i] != i-1) return false;
        return true;
    }
    VI solve(VI color) {
        int n = color.size();
        VI answer(n);
        bool ans = true;
        reprl(i, n-1, 0) {
            answer[i] = ans;
            if (color[i] != color[n-1]) ans = false;
        }
        return answer;
    }
};
namespace TEST3 {
    bool check(VI par) {
        rep(i, par.size()) if (i) {
            if (par[i] != 0 && par[par[i]] != 0) return false;
        }
        return true;
    }
    int n;
    VVI gp;
    VI par;
    VI color;
    set<int> scol(int u) {
        set<int> ret;
        for (int u : gp[u]) ret.insert(color[u]);
        return ret;
    }
    VI solve(int N_ARG, VVI GP_ARG, VI PAR_ARG, VI COLOR_ARG) {
        n = N_ARG;
        gp = GP_ARG;
        par = PAR_ARG;
        color = COLOR_ARG;
        VI answer(n, 1);
        answer[0] = false;
        replr(u, 1, n-1) {
            if (scol(u).size() != gp[u].size()) answer[u] = false;
        }
        set<int> allowed = scol(0);
        if (allowed.size() != gp[0].size()) {
            return answer;
        }
        replr(u, 1, n-1) if (allowed.count(color[u]) == 0) {
            return answer;
        }
        map<int, VI> cnt;
        for (int u : gp[0]) {
            for (int v : gp[u]) {
                cnt[color[v]].pb(u);
            }
        }
        VVI a;
        for (auto& p : cnt) a.pb(p.ss);
        sort(all(a), [&](const VI& a, const VI& b){return a.size() < b.size();});
        VI construct;
        VI ka(n);
        for (VI& vec : a) {
            for (int x : vec) {
                if (ka[x]) continue;
                construct.pb(x);
                ka[x] = true;
            }
            if (construct.size() > vec.size()) {
                return answer;
            }
        }
        answer[0] = true;
        return answer;
    }
};
namespace TEST4 {
    bool check(VI color) {
        map<int, int> cnt;
        for (int x : color) cnt[x]++;
        for (auto& p : cnt) if (p.ss > 2) return false;
        return true;
    }
    int n;
    VVI gp;
    VI par;
    VI color;
    set<int> scol(int u) {
        set<int> ret;
        for (int u : gp[u]) ret.insert(color[u]);
        return ret;
    }
    bool getans(int u) {
        int mec = -1;
        set<int> my = scol(u);
        if (my.size() != gp[u].size()) return false;
        for (int v : gp[u]) {
            if (gp[v].size()) {
                if (mec == -1) mec = v;
                else return false;
            }
        }
        if (mec == -1) return true;
        // mec-i guyner@ pti exnin u-i guyneri entabazmutyun
        for (int v : gp[mec]) {
            if (gp[v].size()) return false;
            if (my.count(color[v]) == 0) return false;
        }
        return true;
    }
    VI solve(int N_ARG, VVI GP_ARG, VI PAR_ARG, VI COLOR_ARG) {
        n = N_ARG;
        gp = GP_ARG;
        par = PAR_ARG;
        color = COLOR_ARG;
        VI ans(n);
        rep(u, n) ans[u] = getans(u);
        return ans;
    }
};

int n;
VVI gp;
VI par;
VI color;

VI answer;
VI dfs(int u = 0) {
    VI ret;
    for (int v : gp[u]) {
        VI his = dfs(v);
        for (int x : his) ret.pb(x);
    }
    bool ardyoq = false;
    ret.pb(u);
    sort(all(ret));
    do {
        if (ret[0] != u) continue;
            VI prev;
            rep(i, ret.size()) if (i) {
                int u = ret[i];
                int cnt = 0;
                for (int v : prev) if (color[v] == color[u]) cnt++;
                if (ret[cnt] != par[u]) goto vat;
                prev.pb(u);
            }
        ardyoq = true;
        break;
        vat:;
    } while (next_permutation(all(ret)));
    answer[u] = ardyoq;
    return ret;
}

VI beechtree(int N, int M, VI P, VI C) {
    n = N;
    par = P;
    color = C;
    gp = VVI(n);
    rep(u, n) if (par[u] != -1) gp[par[u]].pb(u);

    if (TEST2::check(P)) return TEST2::solve(C);
    if (n > 8) {
        if (TEST4::check(color)) return TEST4::solve(n, gp, par, color);
        return TEST3::solve(n, gp, par, color);
    }

    answer = VI(n);
    dfs();
    return answer;
}









# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 404 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 436 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 65 ms 19088 KB Output is correct
8 Correct 54 ms 19016 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 51 ms 18780 KB Output is correct
18 Correct 51 ms 19008 KB Output is correct
19 Correct 52 ms 19008 KB Output is correct
20 Correct 54 ms 19012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 436 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 48 ms 15732 KB Output is correct
16 Correct 37 ms 13524 KB Output is correct
17 Correct 38 ms 13772 KB Output is correct
18 Correct 50 ms 15488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 65 ms 19088 KB Output is correct
6 Correct 54 ms 19016 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 117 ms 31296 KB Output is correct
12 Correct 128 ms 27500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 404 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Incorrect 1 ms 604 KB 2nd lines differ - on the 5th token, expected: '0', found: '1'
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 404 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Incorrect 1 ms 604 KB 2nd lines differ - on the 5th token, expected: '0', found: '1'
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 404 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -