Submission #821310

#TimeUsernameProblemLanguageResultExecution timeMemory
821310QwertyPiCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms212 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}; int pi = 0; for(int x = 1; x <= n; x++){ while(c[1] + c[2] < 2 || r < x) { r++; while(pi < n * 2 && P[pi].x <= r) c[P[pi].y]++, pi++; } if(c[1] == 0){ ans++; c[2] -= 2; }else if(c[2] == 0){ ans++; c[1] -= 2; }else{ c[1]--; c[2]--; } } 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...