Submission #1059539

#TimeUsernameProblemLanguageResultExecution timeMemory
1059539pccFountain Parks (IOI21_parks)C++17
15 / 100
113 ms22516 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second const int mxn = 2e5+10; int N; struct DSU{ int dsu[mxn]; DSU(){ iota(dsu,dsu+mxn,0); } int root(int k){ return k == dsu[k]?k:dsu[k] = root(dsu[k]); } void onion(int a,int b){ dsu[root(a)] = root(b); } }; DSU dsu; vector<int> ans[4]; void addans(int s,int e,int x,int y){ dsu.onion(s,e); ans[0].push_back(s); ans[1].push_back(e); ans[2].push_back(x); ans[3].push_back(y); return; } int construct_roads(std::vector<int> x, std::vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } N = x.size(); vector<int> v[2]; for(int i = 0;i<N;i++){ if(x[i] == 2)v[0].push_back(i); else v[1].push_back(i); } for(auto &i:v)sort(i.begin(),i.end(),[&](int a,int b){return y[a]<y[b];}); map<int,int> mp; for(int i = 0;i<v[0].size();i++){ int now = v[0][i]; mp[y[now]] = now; } for(int i = 0;i<v[1].size();i++){ int now = v[1][i]; if(mp.find(y[now]) != mp.end()){ addans(now,mp[y[now]],x[now]-1,y[now]-1); } } for(int i = 1;i<v[0].size();i++){ int now = v[0][i],pre = v[0][i-1]; if(y[pre]+2 == y[now]&&dsu.root(pre) != dsu.root(now))addans(pre,now,x[now]-1,(y[pre]+y[now])>>1); } for(int i = 1;i<v[1].size();i++){ int now = v[1][i],pre = v[1][i-1]; if(y[pre]+2 == y[now]&&dsu.root(pre) != dsu.root(now))addans(pre,now,x[now]+1,(y[pre]+y[now])>>1); } if(ans[0].size() != N-1)return 0; build(ans[0],ans[1],ans[2],ans[3]); return 1; }

Compilation message (stderr)

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0;i<v[0].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i = 0;i<v[1].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 1;i<v[0].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:65:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 1;i<v[1].size();i++){
      |                ~^~~~~~~~~~~~
parks.cpp:69:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |  if(ans[0].size() != N-1)return 0;
      |     ~~~~~~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...