# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1071463 | Sir_Ahmed_Imran | Beech Tree (IOI23_beechtree) | C++17 | 81 ms | 11192 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define MAXN 200000
int n;
int per[8];
int c[MAXN];
int par[MAXN];
vector<int> s[MAXN];
vector<int> BF(){
per[1]=1;
for(int i=2;i<8;i++)
per[i]=per[i-1]*i;
vector<int> ans;
for(int i=0;i<n;i++){
s[i].append(i);
ans.append(0);
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<per[s[i].size()-1];j++){
next_permutation(s[i].begin()+1,s[i].end());
map<int,int> x;
for(int k=1;k<s[i].size();k++){
if(s[i][x[c[s[i][k]]]]!=par[s[i][k]])
break;
x[c[s[i][k]]]++;
if(k+1==s[i].size()) ans[i]=1;
}
}
if(s[i].size()==1) ans[i]=1;
if(!i) break;
for(auto& j:s[i])
s[par[i]].append(j);
}
return ans;
}
vector<int> beechtree(int N,int M,vector<int> P,vector<int> C){
n=N;
for(int i=0;i<n;i++){
par[i]=P[i];
c[i]=C[i];
}
if(n<9) return BF();
int m=c[n-1];
vector<int> ans;
for(int i=0;i<n;i++)
ans.append(0);
ans[n-1]=1;
for(int i=n-1;i>0;i--){
if(c[i]!=m) break;
ans[i-1]=1;
}
return ans;
}
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... |