#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, x[N], y[N], ans = 0, compressY[2], compressX[N];
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
fw (i, 0, n * 2) cin >> x[i] >> y[i];
//Solve for x and y independently.
//Solving for y.
fw (i, 0, n * 2) {
if (y[i] <= 1) {
compressY[1]++;
ans += (1 - y[i]);
} else {
compressY[2]++;
ans += (y[i] - 2);
}
}
if (compressY[1] > n) ans += compressY[1] - n;
if (compressY[2] > n) ans += compressY[2] - n;
//Transferring extra points from 1 to 2 or vice versa.
fw (i, 0, n * 2) {
if (x[i] < 1) {
compressX[1]++;
ans += (1 - x[i]);
} else if (x[i] > n) {
compressX[n]++;
ans += (x[i] - n);
} else {
compressX[x[i]]++;
}
}
int leftmostGoodColumn = 1;
fw (i, 1, n + 1) {
while (compressX[i] > 2) {
while (leftmostGoodColumn <= n && compressX[leftmostGoodColumn] >= 2) leftmostGoodColumn++;
if (leftmostGoodColumn <= n) {
compressX[leftmostGoodColumn]++;
compressX[i]--;
ans += abs(leftmostGoodColumn - i);
}
}
}
cout << ans;
return 0;
}
Compilation message
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:33:15: warning: array subscript is above array bounds [-Warray-bounds]
compressY[2]++;
~~~~~~~~~~~^
joi2019_ho_t4.cpp:33:15: warning: array subscript is above array bounds [-Warray-bounds]
joi2019_ho_t4.cpp:38:17: warning: array subscript is above array bounds [-Warray-bounds]
if (compressY[2] > n) ans += compressY[2] - n;
~~~~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |