제출 #290250

#제출 시각아이디문제언어결과실행 시간메모리
290250DanerZein늑대인간 (IOI18_werewolf)C++14
0 / 100
4075 ms45256 KiB
#include "werewolf.h" #include <bits/stdc++.h> #define MAX 1000000000 using namespace std; typedef vector<int> vi; typedef pair<int,int> ii; int l,r; bitset<200010> vh,vw; vector<vi> G; void dfs_human(int u){ if(u<l) return; vh[u]=1; for(auto &v:G[u]){ if(!vh[v]){ dfs_human(v); } } } void dfs_wolf(int u){ if(u>r) return; vw[u]=1; for(auto &v:G[u]){ if(!vw[v]){ dfs_wolf(v); } } } map<int,int> m; vector<int> path; int vis[200010]; ii tree[800010]; void dfs(int u){ path.push_back(u); vis[u]=1; for(auto &v: G[u]){ if(!vis[v]){ dfs(v); } } } void init(int node,int a,int b){ if(a>b) return; if(a==b){ tree[node]=ii(path[a],path[a]); return; } int mid=(a+b)/2; init(2*node+1,a,mid); init(2*node+2,mid+1,b); tree[node].first=min(tree[2*node+1].first,tree[2*node+2].first); tree[node].second=max(tree[2*node+1].second,tree[2*node+2].second); } int la,ra,lb,rb; vector<ii> si; ii query_hu(int node,int a,int b,int x,int id){ if(a>b) return ii(-2,-2); if(tree[node].first>=x){ return ii(a,b); } if(a==b) return ii(-2,-2); int mid=(a+b)/2; ii le=query_hu(2*node+1,a,mid,x,id); ii ri=query_hu(2*node+2,mid+1,b,x,id); ii re; if(le.second+1==ri.first){ re=ii(le.first,ri.second); if(re.first<=id and re.second>=id) return re; else return ii(-2,-2); } else{ if(le!=ii(-2,-2)) return le; return ri; if(le.first<=id and le.second>=id) return le; if(ri.first<=id and ri.second>=id) return ri; return le; } } ii query_wolf(int node,int a,int b,int x,int id){ if(a>b) return ii(-2,-2); if(tree[node].second<=x){ return ii(a,b); } if(a==b) return ii(-2,-2); int mid=(a+b)/2; ii le=query_wolf(2*node+1,a,mid,x,id); ii ri=query_wolf(2*node+2,mid+1,b,x,id); ii re; if(le.second+1==ri.first){ re=ii(le.first,ri.second); if(re.first<=id and re.second>=id) return re; else return ii(-2,-2); } else{ if(le.first<=id and le.second>=id) return le; else if(ri.first<=id and ri.second>=id) return ri; else return le; } } std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R) { G.resize(N+1); for(int i=0;i<X.size();i++){ int u=X[i],v=Y[i]; G[u].push_back(v); G[v].push_back(u); } bool sw=0; int id; for(int i=0;i<N;i++){ if(G[i].size()>2){ sw=1; } if(G[i].size()==1) id=i; } vector<int> res; /* if(sw==1){ for(int i=0;i<S.size();i++){ l=L[i]; r=R[i]; vh.reset(); vw.reset(); dfs_human(S[i]); dfs_wolf(E[i]); bool sw=0; for(int i=0;i<N;i++){ if(vh[i]==1 and vw[i]==1){ sw=1; break; } } res.push_back(sw); } }*/ // else{ dfs(id); for(int i=0;i<path.size();i++){ m[path[i]]=i; } init(0,0,N-1); int q=S.size(); for(int i=0;i<q;i++){ sw=0; ii u,v; u=query_hu(0,0,N-1,L[i],m[S[i]]); v=query_wolf(0,0,N-1,R[i],m[E[i]]); la=u.first; ra=u.second; lb=v.first; rb=v.second; // cout<<la<<" "<<ra<<" "<<lb<<" "<<rb<<endl; if((la<=lb and ra>=lb) or (la<=rb and ra>=rb)){ res.push_back(1); } else{ res.push_back(0); } } // } return res; }

컴파일 시 표준 에러 (stderr) 메시지

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:103:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for(int i=0;i<X.size();i++){
      |               ~^~~~~~~~~
werewolf.cpp:137:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |     for(int i=0;i<path.size();i++){
      |                 ~^~~~~~~~~~~~
werewolf.cpp:108:8: warning: variable 'sw' set but not used [-Wunused-but-set-variable]
  108 |   bool sw=0;
      |        ^~
werewolf.cpp:136:8: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
  136 |     dfs(id);
      |     ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...