Submission #980969

# Submission time Handle Problem Language Result Execution time Memory
980969 2024-05-12T16:35:17 Z FZ_Melo Beech Tree (IOI23_beechtree) C++17
0 / 100
2000 ms 28480 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;

struct ari{
    int node, c;
};

int n, m, maxlevel=0;
int buc[200000];
bool used[200000];
bool ya=0;
ari papa[200000];
vector<vector<ari>> adj;
vector<int> perm, nums;


void busca(int node){
    nums.push_back(node);
    for(auto h: adj[node]){
        busca(h.node);
    }
}

void nextperm(int pos){
    if(ya)
        return;
    if(pos==nums.size()){
        for(int i=1; i<perm.size(); i++){
            if(perm[buc[papa[perm[i]].c]]!=papa[perm[i]].node)
                return;
            buc[papa[perm[i]].c]++;
        }
        ya=1;
        return;
    }
    for(int i=0; i<nums.size() && ya==0; i++){
        if(used[nums[i]])
            continue;
        used[nums[i]]=1;
        perm[pos]=nums[i];
        nextperm(pos+1);
        used[nums[i]]=0;
        if(pos==0)
            return;
    }
}

bool checa(int node){
    busca(node);
    perm.clear();
    perm.resize(nums.size());
    nextperm(0);
    return ya;
}

std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
    n=N, m=M;
    adj.resize(n);
    for(int i=1; i<n; i++){
        adj[P[i]].push_back({i, C[i]});
        papa[i]={P[i], C[i]};
    }
    vector<int> ans(n);
    for(int i=0; i<n; i++){
        nums.clear();
        ya=0;
        if(checa(i))
            ans[i]=1;
        for(int j=0; j<=m; j++)
            buc[j]=0;
    }
    return ans;
}

Compilation message

beechtree.cpp: In function 'void nextperm(int)':
beechtree.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(pos==nums.size()){
      |        ~~~^~~~~~~~~~~~~
beechtree.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=1; i<perm.size(); i++){
      |                      ~^~~~~~~~~~~~
beechtree.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0; i<nums.size() && ya==0; i++){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Execution timed out 2082 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2492 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Incorrect 1 ms 2396 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2492 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Execution timed out 2056 ms 28480 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 2392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Execution timed out 2056 ms 28480 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Execution timed out 2082 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Incorrect 1 ms 2396 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Execution timed out 2082 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Incorrect 1 ms 2396 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Execution timed out 2082 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -