Submission #1021062

#TimeUsernameProblemLanguageResultExecution timeMemory
1021062mdn2002Fountain Parks (IOI21_parks)C++17
15 / 100
844 ms109616 KiB
/* Mayoeba Yabureru */ #include "parks.h" #include<bits/stdc++.h> using namespace std; static vector<int> _u, _v, _a, _b; int construct_roads(vector<int> x, vector<int> y) { int n = x.size(); vector<vector<int>> gr(n + 1); x.insert(x.begin(), 0); y.insert(y.begin(), 0); map<pair<int, int>, int> mp; for (int i = 1; i <= n; i ++) mp[{x[i], y[i]}] = i; vector<int> u, v, a, b; map<pair<int, int>, int> taken; for (int i = 1; i <= n; i ++) { if (mp[{x[i] + 2, y[i]}]) { u.push_back(i), v.push_back(mp[{x[i] + 2, y[i]}]); if (taken[{x[i] + 1, y[i] + 1}] == 0) { a.push_back(x[i] + 1), b.push_back(y[i] + 1); taken[{x[i] + 1, y[i] + 1}] = 1; } else if (taken[{x[i] + 1, y[i] - 1}] == 0) { a.push_back(x[i] + 1), b.push_back(y[i] - 1); taken[{x[i] + 1, y[i] - 1}] = 1; } else assert(0); gr[i].push_back(mp[{x[i] + 2, y[i]}]); gr[mp[{x[i] + 2, y[i]}]].push_back(i); } if (mp[{x[i], y[i] + 2}]) { u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]); if (taken[{x[i] + 1, y[i] + 1}] == 0) { a.push_back(x[i] + 1), b.push_back(y[i] + 1); taken[{x[i] + 1, y[i] + 1}] = 1; } else if (taken[{x[i] - 1, y[i] + 1}] == 0) { a.push_back(x[i] - 1), b.push_back(y[i] + 1); taken[{x[i] - 1, y[i] + 1}] = 1; } else assert(0); gr[i].push_back(mp[{x[i], y[i] + 2}]); gr[mp[{x[i], y[i] + 2}]].push_back(i); } } for (int i = 0; i < u.size(); i ++) { u[i] --; v[i] --; } int num = 0; vector<int> vis(n + 1); function<void(int)> go = [&] (int x) { num ++; vis[x] = 1; for (auto u : gr[x]) { if (vis[u]) continue; go(u); } }; go(1); if (num == n) { 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:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int i = 0; i < u.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...