# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973482 | irmuun | Beech Tree (IOI23_beechtree) | C++17 | 2077 ms | 17756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "beechtree.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
vector<int>beechtree(int n,int m,vector<int>p,vector<int>c){
vector<int>g[n];
bool line=true;
for(int i=1;i<n;i++){
g[p[i]].pb(i);
line&=(p[i]+1==i);
}
vector<int>b(n);
if(line){
bool ok=true;
b[n-1]=1;
b[n-2]=1;
for(int i=n-3;i>=0;i--){
if(c[i+1]==c[i+2]){
b[i]=1;
}
else{
break;
}
}
return b;
}
for(int i=1;i<n;i++){
c[i]--;
}
vector<int>f(m);
for(int r=0;r<n;r++){
vector<int>u;
queue<int>q;
q.push(r);
while(!q.empty()){
int x=q.front();
u.pb(x);
q.pop();
for(int y:g[x]){
q.push(y);
}
}
sort(all(u));
bool can=false;
do{
fill(all(f),0);
bool flag=true;
if(u[0]!=r){
continue;
}
for(int i=1;i<u.size();i++){
if(p[u[i]]!=u[f[c[u[i]]]]){
flag=false;
}
f[c[u[i]]]++;
}
if(flag){
can=true;
}
}while(next_permutation(all(u)));
if(can){
b[r]=1;
}
}
return b;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |