Submission #436732

#TimeUsernameProblemLanguageResultExecution timeMemory
436732PiejanVDCFountain Parks (IOI21_parks)C++17
Compilation error
0 ms0 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; int construct_roads(vector<int>x, vector<int> y) { vector<pair<int,int>>two,four; for(int i = 0 ; i < y.size() ; i++) { if(x[i] == 2) two.push_back({y[i,i}); else four.push_back({y[i,i}); } vector<int>adj[x.size()]; vector<int>u,v,a,b; sort(two.begin(),two.end()); sort(four.begin(),four.end()); for(int i = 0 ; i < (int)two.size()-1 ; i++) { if(two[i+1].first-two[i].first == 2) { u.push_back(two[i].second); v.push_back(two[i+1].second); a.push_back(1); b.push_back(two[i].first+1); adj[two[i].second].push_back(two[i+1].second); adj[two[i+1].second].push_back(two[i].second); } } for(int i = 0 ; i < (int)four.size()-1 ; i++) { if(four[i+1].first-four[i].first == 2) { u.push_back(four[i].second); v.push_back(four[i+1].second); a.push_back(1); b.push_back(four[i].first+1); adj[four[i].second].push_back(four[i+1].second); adj[four[i+1].second].push_back(four[i].second); } } if((int)two.size() > 0 && (int)four.size() > 0) { for(int i = 0 ; i < two.size() ; i++) { int left=0,right=four.size(); while(left <= right) { int mid = (left+right)/2; if(four[mid].first == two[i].first) { u.push_back(two[i].second); v.push_back(four[i].second); a.push_back(3); b.push_back(two[i].first); adj[two[i].second].push_back(four[mid].second); adj[four[mid].second].push_back(two[i].second); break; } if(four[mid].first < two[i].first) { left=mid+1; } else { right=mid-1; } } } } stack<int>s; s.push(0); vector<bool>vis(x.size(),false); while(!s.empty()) { int node = s.top(); s.pop(); vis[node]=true; for(auto z : adj[node]) { if(!vis[z]) s.push(z); } } bool f=true; for(auto z : vis) { if(!z) { f=false; break; } } if(f) { build(u,v,a,b); return 1; } return 0; }

Compilation message (stderr)

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i = 0 ; i < y.size() ; i++) {
      |                     ~~^~~~~~~~~~
parks.cpp:8:40: warning: left operand of comma operator has no effect [-Wunused-value]
    8 |         if(x[i] == 2) two.push_back({y[i,i});
      |                                        ^
parks.cpp:8:43: error: expected ']' before '}' token
    8 |         if(x[i] == 2) two.push_back({y[i,i});
      |                                           ^
      |                                           ]
parks.cpp:8:44: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
    8 |         if(x[i] == 2) two.push_back({y[i,i});
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from parks.h:1,
                 from parks.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
parks.cpp:9:32: warning: left operand of comma operator has no effect [-Wunused-value]
    9 |         else four.push_back({y[i,i});
      |                                ^
parks.cpp:9:35: error: expected ']' before '}' token
    9 |         else four.push_back({y[i,i});
      |                                   ^
      |                                   ]
parks.cpp:9:36: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
    9 |         else four.push_back({y[i,i});
      |                                    ^
In file included from /usr/include/c++/10/vector:67,
                 from parks.h:1,
                 from parks.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
parks.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0 ; i < two.size() ; i++) {
      |                         ~~^~~~~~~~~~~~