# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201262 | abil | Coin Collecting (JOI19_ho_t4) | C++14 | 100 ms | 6088 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int inf = (1e9 + 7);
int a[N][3];
main(){
int n, x, y;
long long ans = 0;
cin >> n;
for(int i = 1;i <= 2 * n; i++){
scanf("%lld%lld", &x, &y);
if(x < 1){
ans += 1 - x;
x = 1;
}
if(x > n){
ans += x - n;
x = n;
}
if(y < 1){
ans += 1 - y;
y = 1;
}
if(y > 2){
ans += y - 2;
y = 2;
}
a[x][y]++;
}
int cnt1 = 0, cnt2 = 0;
for(int i = 1;i <= n; i++){
cnt1 += a[i][1] - 1;
cnt2 += a[i][2] - 1;
if(cnt1 > 0 && cnt2 < 0){
int x = min(cnt1, -cnt2);
ans += x;
cnt1 -= x;
cnt2 += x;
}
if(cnt2 > 0 && cnt1 < 0){
int x = min(cnt2, -cnt1);
ans += x;
cnt2 -= x;
cnt1 += x;
}
ans += abs(cnt1);
ans += abs(cnt2);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |