# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153321 | mhy908 | Coin Collecting (JOI19_ho_t4) | C++14 | 78 ms | 4988 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 F first
#define S second
#define pb push_back
#define llinf 8987654321987654321
#define inf 1987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
LL ans;
int cnt[100010][3], temp1, temp2;
int n;
int main()
{
scanf("%d", &n);
for(int i=1; i<=2*n; i++){
LL x, y;
scanf("%lld %lld", &x, &y);
if(x<1)ans+=1-x, x=1;
if(x>n)ans+=x-(LL)n, x=(LL)n;
if(y<1)ans+=1-y, y=1;
if(y>2)ans+=y-2, y=2;
cnt[(int)x][(int)y]++;
}
for(int i=1; i<=n; i++){
temp1+=cnt[i][1]-1;
temp2+=cnt[i][2]-1;
if(temp1>0&&temp2<0){
int t=min(temp1, -temp2);
ans+=(LL)t;
temp1-=t;
temp2+=t;
}
if(temp1<0&&temp2>0){
int t=min(-temp1, +temp2);
ans+=(LL)t;
temp1+=t;
temp2-=t;
}
ans+=llabs((LL)temp1)+llabs((LL)temp2);
}
printf("%lld", 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... |