Submission #1079358

#TimeUsernameProblemLanguageResultExecution timeMemory
1079358raphaelpTiles (BOI24_tiles)C++14
100 / 100
175 ms16744 KiB
#include <bits/stdc++.h> using namespace std; struct segment { int l, r, par; }; bool operator<(segment a, segment b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; } void add(vector<int> arete, int &impair, vector<int> &parity, set<segment> &Intervals) { if ((arete[2] - arete[1] + 1) % 2 == 1) impair++; parity[arete[0] % 2]++; Intervals.insert({arete[1], arete[2], arete[0] % 2}); } int N; int next(int i) { return (i + 1) % N; } int main() { int M; cin >> N >> M; vector<vector<int>> arete; vector<int> X(N), Y(N); for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } for (int i = 0; i < N; i++) { if (X[next(i)] == X[i]) { if (Y[i] < Y[next(i)]) arete.push_back({X[i], min(Y[i], Y[next(i)]), max(Y[i], Y[next(i)]) - 1, 1}); else arete.push_back({X[i], min(Y[i], Y[next(i)]), max(Y[i], Y[next(i)]) - 1, -1}); } } sort(arete.begin(), arete.end()); if (arete[0][3] == -1) for (int i = 0; i < arete.size(); i++) arete[i][3] = 0 - arete[i][3]; int last = -1; int impair = 0; vector<int> parity(2); int maxx = 0; set<segment> Intervals; for (int i = 0; i < arete.size(); i++) { if (arete[i][0] != last || i == arete.size() - 1) { last = arete[i][0]; if (impair) break; if (parity[0] == 0 || parity[1] == 0) { int par = ((parity[1]) ? 1 : 0); maxx = ((arete[i][0] % 2 == par) ? arete[i][0] : (arete[i][0] - 1)); } } if (arete[i][3] == 1) { auto pos = Intervals.lower_bound({arete[i][1]}); if (pos != Intervals.end() && (*pos).l == arete[i][2] + 1 && (*pos).par == (arete[i][0] % 2)) { arete[i][2] = (*pos).r; if (((*pos).r - (*pos).l + 1) % 2) impair--; parity[(*pos).par]--; pos = Intervals.erase(pos); } if (pos != Intervals.begin()) { pos--; if ((*pos).r == arete[i][1] - 1 && (*pos).par == (arete[i][0] % 2)) { arete[i][1] = (*pos).l; if (((*pos).r - (*pos).l + 1) % 2) impair--; parity[(*pos).par]--; Intervals.erase(pos); } } add(arete[i], impair, parity, Intervals); } else { auto pos = Intervals.upper_bound({arete[i][2], 1000000000}); pos--; if ((arete[i][0] % 2) != (*pos).par) break; if (arete[i][1] < (*pos).l) break; int left = (*pos).l, right = arete[i][1] - 1; if (right >= left) { add({(*pos).par, left, right}, impair, parity, Intervals); } left = arete[i][2] + 1, right = (*pos).r; if (right >= left) { add({(*pos).par, left, right}, impair, parity, Intervals); } parity[(*pos).par]--; if (((*pos).r - (*pos).l + 1) % 2) impair--; Intervals.erase(pos); } } cout << maxx; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int i = 0; i < arete.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
Main.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < arete.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
Main.cpp:54:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if (arete[i][0] != last || i == arete.size() - 1)
      |                                    ~~^~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...