# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117916 | songc | Coin Collecting (JOI19_ho_t4) | C++14 | 73 ms | 2552 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 MOD 1000000007
#define INF 1234567890
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N;
int A[2][101010];
LL ans;
int main(){
int x, y, k;
scanf("%d", &N);
for (int i=1; i<=2*N; i++){
scanf("%d %d", &x, &y);
if (y <= 1) ans += 1-y, y=1;
else ans += y-2, y=2;
if (x <= 1) ans += 1-x, x=1;
else if (x >= N) ans += x-N, x=N;
A[y-1][x]++;
}
for (int i=1; i<=N; i++){
if (A[0][i] < 1 && A[1][i] > 1){
k = min(1-A[0][i], A[1][i]-1);
ans += k, A[0][i] += k, A[1][i] -= k;
}
if (A[1][i] < 1 && A[0][i] > 1){
k = min(1-A[1][i], A[0][i]-1);
ans += k, A[1][i] += k, A[0][i] -= k;
}
A[0][i+1] += A[0][i]-1, ans += abs(A[0][i]-1);
A[1][i+1] += A[1][i]-1, ans += abs(A[1][i]-1);
}
printf("%lld\n", ans);
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... |