#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
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;
| ~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |