# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511032 | blue | Coin Collecting (JOI19_ho_t4) | C++17 | 0 ms | 204 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vvi A(1+2, vi(1+N, 0));
ll ans = 0;
for(int i = 1; i <= 2*N; i++)
{
int X, Y;
cin >> 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][X]++;
}
for(int i = 1; i <= N; i++)
{
A[1][i]--;
A[2][i]--;
ll mov = 0;
if(A[1][i] >= 0 && A[2][i] < 0)
{
mov = min(A[1][i], -A[2][i]);
}
else if(A[1][i] < 0 && A[2][i] >= 0)
{
mov = max(A[1][i], -A[2][i]);
}
// A[1][i] -= mov;
// A[2][i] += mov;
// ans += abs(mov);
if(i < N)
{
A[1][i+1] += A[1][i];
A[2][i+1] += A[2][i];
ans += abs(A[1][i]);
ans += abs(A[2][i]);
}
}
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... |