Submission #821419

#TimeUsernameProblemLanguageResultExecution timeMemory
821419QwertyPiCoin Collecting (JOI19_ho_t4)C++14
100 / 100
148 ms8248 KiB
#include <bits/stdc++.h> #define int long long using namespace std; struct point{ int x, y; bool operator< (const point& o) const { return x < o.x || x == o.x && y < o.y; } }; int32_t main() { int n; cin >> n; int ans = 0; vector<point> P; for(int i = 0; i < n * 2; i++){ int x, y; cin >> x >> y; if(x < 1) ans += abs(x - 1), x = 1; if(x > n) ans += abs(x - n), x = n; if(y < 1) ans += abs(y - 1), y = 1; if(y > 2) ans += abs(y - 2), y = 2; P.push_back({x, y}); } sort(P.begin(), P.end()); for(int i = 0; i < n * 2; i++) ans += abs(P[i].x - (i / 2 + 1)); int r = 0, c[3] = {0, 0, 0}, m[3] = {0, 0, 0}; int pi = 0; for(int x = 1; x <= n; x++){ while(r < x) { r++; while(pi < n * 2 && P[pi].x <= r) c[P[pi].y]++, pi++; } m[1]++; m[2]++; for(int y = 1; y <= 2; y++){ while(c[y] > 0 && m[y] > 0) c[y]--, m[y]--; } for(int y = 1; y <= 2; y++){ while(c[y] > 0 && m[3 - y] > 0) c[y]--, m[3 - y]--, ans++; } } cout << ans << endl; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In member function 'bool point::operator<(const point&) const':
joi2019_ho_t4.cpp:8:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    8 |   return x < o.x || x == o.x && y < o.y;
      |                     ~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...