Submission #1039052

# Submission time Handle Problem Language Result Execution time Memory
1039052 2024-07-30T11:48:11 Z fv3 Beech Tree (IOI23_beechtree) C++17
9 / 100
2000 ms 36048 KB
#include <bits/stdc++.h>
#include "beechtree.h"

using namespace std;
vector<int> b, p, c;
vector<vector<int>> adj;

void solve(int index)
{
    vector<int> children;
    queue<int> q;
    q.push(index);

    while (!q.empty())
    {
        int s = q.front();
        q.pop();
        for (auto node : adj[s])
        {
            children.push_back(node);
            q.push(node);
        }
    }

    b[index] = 1;
    if (!children.size())
        return;

    sort(children.begin(), children.end());
    do
    {
        map<int, int> cnt;
        map<int, int> label;
        label[index] = 0;
        for (int i = 0; i < children.size(); i++)
            label[children[i]] = i+1;

        if (index == 0)
        {
            for (auto e : label)
                cerr << e.second << ' ';
            cerr << "= ";
        }

        bool ok = true;
        for (auto child : children)
        {
            if (cnt[c[child]] != label[p[child]])
            {
                cerr << child << ", " << label[p[child]] << ", " << cnt[c[child]] << '\n';
                ok = false;
                break;
            }
            cnt[c[child]]++;
        }
        if (ok)
        {
            return;
        }
    } while (next_permutation(children.begin(), children.end()));

    b[index] = 0;
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
    p = P; c = C;
    b = vector<int>(N);
    adj = vector<vector<int>>(N);

    for (int i = 1; i < N; i++)
        adj[P[i]].push_back(i);

    for (int i = 0; i < N; i++)
    {
        solve(i);
    }

    return b;
}

Compilation message

beechtree.cpp: In function 'void solve(int)':
beechtree.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 0; i < children.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 2096 ms 3160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 113 ms 476 KB Output is correct
5 Correct 118 ms 348 KB Output is correct
6 Correct 121 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 15 ms 440 KB Output is correct
10 Correct 15 ms 348 KB Output is correct
11 Correct 15 ms 344 KB Output is correct
12 Correct 15 ms 600 KB Output is correct
13 Correct 15 ms 348 KB Output is correct
14 Correct 15 ms 456 KB Output is correct
15 Correct 15 ms 344 KB Output is correct
16 Correct 15 ms 348 KB Output is correct
17 Correct 15 ms 436 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 15 ms 440 KB Output is correct
23 Correct 15 ms 348 KB Output is correct
24 Correct 15 ms 348 KB Output is correct
25 Correct 19 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 15 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 15 ms 448 KB Output is correct
32 Correct 113 ms 348 KB Output is correct
33 Correct 15 ms 344 KB Output is correct
34 Correct 0 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 113 ms 476 KB Output is correct
5 Correct 118 ms 348 KB Output is correct
6 Correct 121 ms 464 KB Output is correct
7 Execution timed out 2075 ms 36048 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2055 ms 3668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 2075 ms 36048 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 2096 ms 3160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 15 ms 440 KB Output is correct
6 Correct 15 ms 348 KB Output is correct
7 Correct 15 ms 344 KB Output is correct
8 Correct 15 ms 600 KB Output is correct
9 Correct 15 ms 348 KB Output is correct
10 Correct 15 ms 456 KB Output is correct
11 Correct 15 ms 344 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 15 ms 436 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 15 ms 440 KB Output is correct
19 Correct 15 ms 348 KB Output is correct
20 Correct 15 ms 348 KB Output is correct
21 Correct 19 ms 600 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 198 ms 604 KB Output is correct
26 Execution timed out 2045 ms 5316 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 2096 ms 3160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 15 ms 440 KB Output is correct
6 Correct 15 ms 348 KB Output is correct
7 Correct 15 ms 344 KB Output is correct
8 Correct 15 ms 600 KB Output is correct
9 Correct 15 ms 348 KB Output is correct
10 Correct 15 ms 456 KB Output is correct
11 Correct 15 ms 344 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 15 ms 436 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 15 ms 440 KB Output is correct
19 Correct 15 ms 348 KB Output is correct
20 Correct 15 ms 348 KB Output is correct
21 Correct 19 ms 600 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 198 ms 604 KB Output is correct
26 Execution timed out 2045 ms 5316 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 2096 ms 3160 KB Time limit exceeded
3 Halted 0 ms 0 KB -