# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1079727 | _rain_ | Coin Collecting (JOI19_ho_t4) | C++14 | 42 ms | 5044 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>
using namespace std;
#define ll long long
#define fixbug true
void SETIO(string name = ""){
if (name=="") return;
freopen((name+".inp").c_str(),"r",stdin);
// freopen((name+".out").c_str(),"w",stdout);
return;
}
const int maxn = 2e5;
int in[maxn+2][3] = {} , n;
ll ans = 0 , cur[3];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
SETIO("");
cin >> n;
ll ans = 0;
for (int i = 1; i <= 2*n; ++i) {
int x , y; cin >> x >> y;
if (x < 1) ans += abs(1 - x) , 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;
in[x][y]++;
}
for (int i = 1; i <= n; ++i){
cur[1] += in[i][1] - 1;
cur[2] += in[i][2] - 1;
if (cur[2] * cur[1] < 0){
ll x = min(abs(cur[2]) , abs(cur[1]));
if (cur[2] > 0){
cur[2] -= x;
cur[1] += x;
ans += x;
}
else{
cur[2] += x;
cur[1] -= x;
ans += x;
}
}
ans += abs(cur[2]) + abs(cur[1]);
}
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... |