# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125577 | wilwxk | 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;
typedef long long ll;
const int MAXN=2e3+5;
const ll INF=1e15+9;
vector<ll> v;
int n, cont;
ll respf;
int main() {
scanf("%d", &n); n*=2;
for(int i=1; i<=n; i++) {
int a, b; scanf("%d %d", &a, &b);
if(a<1||a>n) {
if(a<1) respf+=1-a, a=1;
else respf+=a-n, a=n;
}
if(b>=2) cont++;
respf+=min(abs(b-1), abs(b-2));
v.push_back(a);
}
respf+=abs(n/2-cont);
sort(v.begin(), v.end());
int ind=0;
for(int i=0; i<n; i++) {
ll cur=i/2+1;
// printf("adsby %d %lld //%lld\n", cur, ind, respf);
respf+=abs(v[ind++]-cur);
}
printf("%lld\n", respf);
}
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... |