# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122923 | Hideo | Coin Collecting (JOI19_ho_t4) | C++14 | 2 ms | 376 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 pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, ll >
#define pii pair < int, pi >
#define vii vector < pi >
const int N = 3e5 + 7;
const int INF = 1e9 + 7;
int a[N][3];
int n, ans;
void close (ll &v, int r){
if (v < 1){
ans += abs(1 - v);
v = 1;
}
if (v > r){
ans += abs(r - v);
v = r;
}
}
main(){
cin >> n;
ll x, y;
for (int i = 1; i <= 2 * n; i++){
scanf("%lld%lld", &x, &y);
close(x, n);
close(y, 2);
a[x][y]++;
}
for (int i = 1; i <= n; i++){
if (min(a[i][1], a[i][2]) <= 0 && max(a[i][1], a[i][2]) > 0){
ans += abs(min(a[i][1], a[i][2]));
if (a[i][1] < a[i][2]){
a[i][2] -= abs(a[i][1]);
a[i][1] = 1;
}
else {
a[i][1] -= abs(a[i][2]);
a[i][2] = 1;
}
}
a[i][1]--; a[i][2]--;
ans += abs(a[i][1]) + abs(a[i][2]);
a[i + 1][1] += a[i][1];
a[i + 1][2] += a[i][2];
}
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... |