# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958785 | raphaelp | Coin Collecting (JOI19_ho_t4) | C++14 | 1 ms | 364 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;
int main()
{
long long N;
cin >> N;
vector<long long> X(N * 2), Y(N * 2);
for (long long i = 0; i < 2 * N; i++)
{
cin >> X[i] >> Y[i];
}
long long tot = 0;
for (long long i = 0; i < 2 * N; i++)
{
if (Y[i] > 2)
{
tot += Y[i] - 2;
Y[i] = 2;
}
}
for (long long i = 0; i < 2 * N; i++)
{
if (X[i] > N)
{
tot += X[i] - N;
X[i] = N;
}
}
for (long long i = 0; i < 2 * N; i++)
{
if (Y[i] <= 0)
{
tot -= Y[i] - 1;
Y[i] = 1;
}
}
for (long long i = 0; i < 2 * N; i++)
{
if (X[i] <= 0)
{
tot -= X[i] - 1;
X[i] = 1;
}
}
vector<long long> one, two;
for (long long i = 0; i < 2 * N; i++)
{
if (Y[i] == 1)
one.push_back(X[i]);
else
two.push_back(X[i]);
}
sort(one.begin(), one.end());
sort(two.begin(), two.end());
one.push_back(1234567890);
two.push_back(1234567890);
long long buff1 = 0, buff2 = 0;
for (long long i = 1; i <= N; i++)
{
int done1 = 0, done2 = 0;
if (one[buff1] == i)
{
done1 = 1;
buff1++;
}
if (two[buff2] == i)
{
done2 = 1;
buff2++;
}
if (!done1)
if (one[buff1] <= two[buff2])
{
tot += abs(one[buff1] - i);
buff1++;
}
else
{
tot += abs(two[buff2] - i) + 1;
buff2++;
}
if (!done2)
if (one[buff1] < two[buff2])
{
tot += abs(one[buff1] - i) + 1;
buff1++;
}
else
{
tot += abs(two[buff2] - i);
buff2++;
}
}
cout << tot;
}
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... |