Submission #970305

#TimeUsernameProblemLanguageResultExecution timeMemory
970305mychecksedadFountain Parks (IOI21_parks)C++17
15 / 100
127 ms22452 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n'; #define ll long long int const int N = 3e5+10; struct Dsu{ vector<int> s, p; Dsu(int n){ s.resize(n, 1); p.resize(n); for(int i = 0; i < n; ++i) p[i] = i; } int find(int v){ if(p[v] == v) return v; return p[v] = find(p[v]); } void merge(int a, int b){ a = find(a); b = find(b); if(a != b){ if(s[a] > s[b]) swap(a, b); p[a] = b; s[b] += s[a]; } } }; int construct_roads(std::vector<int> x, std::vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } int n = x.size(); vector<int> u, v, a, b; Dsu d(n); vector<pair<int, int>> L, R; for(int i = 0; i < n; ++i){ if(x[i] == 2) L.pb({y[i], i}); else R.pb({y[i], i}); } sort(all(L)); sort(all(R)); for(int i = 0; i + 1 < L.size(); ++i){ if(L[i].first < L[i + 1].first - 2) continue; u.pb(L[i].second); v.pb(L[i + 1].second); a.pb(1); b.pb(L[i + 1].first + L[i].first>>1); d.merge(L[i].second, L[i + 1].second); } for(int i = 0; i + 1 < R.size(); ++i){ if(R[i].first < R[i + 1].first - 2) continue; u.pb(R[i].second); v.pb(R[i + 1].second); a.pb(5); b.pb(R[i + 1].first + R[i].first>>1); d.merge(R[i].second, R[i + 1].second); } if(!R.empty() && !L.empty()){ int p = 0; for(int i = 0; i < L.size(); ++i){ while(R[p].first < L[i].first) ++p; if(L[i].first == R[p].first){ u.pb(L[i].second); v.pb(R[p].second); a.pb(3); b.pb(L[i].first - 1); d.merge(L[i].second, R[p].second); } } } if(d.s[d.find(0)] < n) return 0; build(u, v, a, b); return 1; }

Compilation message (stderr)

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i + 1 < L.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:56:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         b.pb(L[i + 1].first + L[i].first>>1);
parks.cpp:59:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i = 0; i + 1 < R.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:64:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |         b.pb(R[i + 1].first + R[i].first>>1);
parks.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i = 0; i < L.size(); ++i){
      |                        ~~^~~~~~~~~~
#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...