이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "beechtree.h"
#include <algorithm>
#include <map>
using namespace std;
int n,m;
vector<int>p,c,ans;
vector<vector<int>>v;
vector<int>subtree;
void dfs(int x){
subtree.push_back(x);
for(int z:v[x]){
dfs(z);
}
}
bool check(vector<int>s){
map<int,int>m;
for(int i=1;i<s.size();i++){
if(s[m[c[s[i]]]]!=p[s[i]]) return false;
m[c[s[i]]]++;
}
return true;
}
void sub1(){
for(int i=0;i<n;i++){
dfs(i);
sort(subtree.begin(),subtree.end());
do{
if(check(subtree)){
ans[i]=1;
break;
}
}while(next_permutation(subtree.begin(),subtree.end()));
subtree.clear();
}
}
void sub2(){
ans[n-1]=ans[n-2]=1;
int j=n-2;
while(j>0 && c[j]==c[j+1]){
ans[--j]=1;
}
}
vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
n=N,m=M;
swap(p,P);
swap(c,C);
v.resize(n);
bool sui2=true;
for(int i=1;i<n;i++){
if(p[i]!=i-1) sui2=false;
v[p[i]].push_back(i);
}
ans.resize(n);
if(n<=8) sub1();
else if(sui2) sub2();
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
beechtree.cpp: In function 'bool check(std::vector<int>)':
beechtree.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
# | 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... |