# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730434 | speedyArda | Coin Collecting (JOI19_ho_t4) | C++14 | 193 ms | 7320 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;
using ll = long long;
const int MAXN = 1e5+5;
ll cnt[MAXN][3];
int main()
{
int n;
cin >> n;
ll ans = 0;
for(int i = 1; i <= 2 * n; i++)
{
int x, y;
cin >> x >> y;
if(x <= 1) {
ans += 1 - x;
x = 1;
}
else if(x > n) {
ans += x - n;
x = n;
}
if(y <= 1) {
ans += 1 - y;
y = 1;
}
else {
ans += y - 2;
y = 2;
}
cnt[x][y]++;
}
ll up = 1, down = 1;
ll remup = 0, remdown = 0;
for(int pr=1; pr<=n ;pr++){
while(up<=pr && cnt[pr][1]>0) ans+=pr-up++,cnt[pr][1]--;
while(down<=pr && cnt[pr][2]>0) ans+=pr-down++,cnt[pr][2]--;
while(up>pr && down<=pr && cnt[pr][1]>0) ans+=pr+1-down++,cnt[pr][1]--;
while(down>pr && up<=pr && cnt[pr][2]>0) ans+=pr+1-up++,cnt[pr][2]--;
ans+=cnt[pr][1];cnt[pr+1][1]+=cnt[pr][1];cnt[pr][1]=0;
ans+=cnt[pr][2];cnt[pr+1][2]+=cnt[pr][2];cnt[pr][2]=0;
}
cout << ans << "\n";
}
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... |