| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1309725 | StefanSebez | Coin Collecting (JOI19_ho_t4) | C++20 | 42 ms | 1196 KiB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
const int N=1e5+50;
int a[N][2];
int main(){
int n;scanf("%i",&n);
ll res=0;
for(int i=1;i<=2*n;i++){
int x,y;scanf("%i%i",&x,&y);
if(y<1)res+=1-y,y=1;
if(y>2)res+=y-2,y=2;
if(x<1)res+=1-x,x=1;
if(x>n)res+=x-n,x=n;
a[x][y-1]++;
}
for(int i=1;i<=n;i++){
a[i][0]--;
a[i][1]--;
int x=min(abs(a[i][0]),abs(a[i][1]));
if(a[i][0]<0&&a[i][1]>0){
a[i][0]+=x,a[i][1]-=x;
res+=x;
}
if(a[i][0]>0&&a[i][1]<0){
a[i][0]-=x,a[i][1]+=x;
res+=x;
}
a[i+1][0]+=a[i][0];
a[i+1][1]+=a[i][1];
res+=abs(a[i][0])+abs(a[i][1]);
}
printf("%lld\n",res);
return 0;
}
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... | ||||
