Submission #588051

#TimeUsernameProblemLanguageResultExecution timeMemory
588051Clan328Fountain Parks (IOI21_parks)C++17
5 / 100
115 ms18468 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; #define pb push_back struct Coord { int x, y, i; bool operator<(Coord other) const { if (y == other.y) { return x < other.x; } return y < other.y; } }; int n; vector<Coord> coords; std::vector<int> u, v, a, b; void connect(int i, int j) { if (coords[i].x == coords[j].x) { u.pb(coords[i].i); v.pb(coords[j].i); a.pb(coords[i].x+1); b.pb(coords[i].y+1); } else if (coords[i].y == coords[j].y) { u.pb(coords[i].i); v.pb(coords[j].i); a.pb(coords[i].x+1); b.pb(coords[i].y-1); } } int construct_roads(std::vector<int> x, std::vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } n = x.size(); vector<pair<int, int>> yi(n); coords = vector<Coord>(n); for (int i = 0; i < n; i++) { coords[i] = {x[i], y[i], i}; } sort(coords.begin(), coords.end()); bool res = true; for (int i = 0; i < n-1; i++) { bool isValid = false; if ((coords[i].y+2 == coords[i+1].y && coords[i].x == coords[i+1].x) || (coords[i].y == coords[i+1].y && coords[i].x+2 == coords[i+1].x)) { connect(i, i+1); isValid = true; } else if (i+2 < n && (coords[i].y+2 == coords[i+2].y && coords[i].x == coords[i+2].x) || (coords[i].y == coords[i+2].y && coords[i].x+2 == coords[i+2].x)) { connect(i, i+2); isValid = true; } res &= isValid; } if (!res) return 0; // int maxY = 0; // for (int i = 0; i < y.size(); i++) maxY = max(maxY, y[i]); // vvi mat(maxY/2-1, vi(3)), matIdx(maxY/2-1, vi(3)); // for (int i = 0; i < x.size(); i++) { // mat[x[i]/2-1][y[i]/2-1] = 1; // matIdx[x[i]/2-1][y[i]/2-1] = i; // } 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:58:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   58 |         } else if (i+2 < n && (coords[i].y+2 == coords[i+2].y && coords[i].x == coords[i+2].x) || (coords[i].y == coords[i+2].y && coords[i].x+2 == coords[i+2].x)) {
      |                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...