Submission #295758

#TimeUsernameProblemLanguageResultExecution timeMemory
295758eohomegrownappsWerewolf (IOI18_werewolf)C++14
0 / 100
1833 ms48888 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; vector<int> l; vector<int> r; int n,q; vector<vector<int>> adjlist; bool comp_l(int a, int b){ return l[a]<l[b]; } bool comp_r(int a, int b){ return r[a]>r[b]; } 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) { q = s.size(); l=L;r=R;n=N; adjlist.resize(n); for (int i = 0; i<x.size(); i++){ //cout<<x[i]<<' '<<y[i]<<endl; adjlist[x[i]].push_back(y[i]); adjlist[y[i]].push_back(x[i]); } int start = -1; for (int i = 0; i<n; i++){ if (adjlist[i].size()==1){ start=i; break; } } int cur = start; int pre = -1; int ptr = 0; int pop2ind[200005]; int ind2pop[200005]; do { pop2ind[cur]=ptr; ind2pop[ptr]=cur; if (adjlist[cur][0]==pre){ pre=cur; cur=adjlist[cur][1]; } else { pre=cur; cur=adjlist[cur][0]; } ptr++; } while (adjlist[cur].size()!=1); pop2ind[cur]=ptr; ind2pop[ptr]=cur; /*for (int i = 0; i<n; i++){ cout<<ind2pop[i]<<' '; }cout<<'\n';*/ vector<int> intsl(q); vector<int> intsr(q); vector<int> intel(q); vector<int> inter(q); vector<int> inds(q); //cout<<"blehhh"<<endl; for (int i = 0; i<q; i++){ inds[i]=i; } //cout<<"blehhh"<<endl; /*for (int i : l){ cout<<i<<' '; }cout<<endl; for (int i : r){ cout<<i<<' '; }cout<<endl;*/ sort(inds.begin(), inds.end(), comp_l); //cout<<"blehhh"<<endl; int prevl = 0; set<int> lpoints; lpoints.insert(-1); lpoints.insert(n); for (int i = 0; i<q; i++){ cout<<i<<endl; while (prevl<l[inds[i]]){ lpoints.insert(pop2ind[prevl]); prevl++; } auto lb = lpoints.lower_bound(pop2ind[s[inds[i]]]); intsl[inds[i]]=*(prev(lb))+1; intsr[inds[i]]=*lb-1; } sort(inds.begin(), inds.end(), comp_r); int prevr = n-1; set<int> rpoints; rpoints.insert(-1); rpoints.insert(n); for (int i = 0; i<q; i++){ cout<<i<<endl; while (prevr>r[inds[i]]){ rpoints.insert(pop2ind[prevr]); prevr--; } auto lb = rpoints.lower_bound(pop2ind[e[inds[i]]]); intel[inds[i]]=*(prev(lb))+1; inter[inds[i]]=*lb-1; } vector<int> ans(q); for (int i = 0; i<q; i++){ //cout<<"human: "<<intsl[i]<<' '<<intsr[i]<<'\n'; //cout<<"werewolf: "<<intel[i]<<' '<<inter[i]<<'\n'; if (!(inter[i]<intsl[i]||intsr[i]<intel[i])){ ans[i]=1; } else { ans[i]=0; } } return ans; }

Compilation message (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:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i<x.size(); i++){
      |                     ~^~~~~~~~~
werewolf.cpp:43:9: warning: variable 'ind2pop' set but not used [-Wunused-but-set-variable]
   43 |     int ind2pop[200005];
      |         ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...