# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943763 | tset | Coin Collecting (JOI19_ho_t4) | C++17 | 47 ms | 10400 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;
#define int long long
signed main()
{
int nbLigs = 2,nbCols;
scanf("%lld", &nbCols);
vector<pair<int,int>> pts;
for(int iPt =0; iPt<2*nbCols; iPt++)
{
int col, lig;
scanf("%lld%lld", &col, &lig);
pts.push_back({lig, col});
}
int res = 0;
vector<vector<int> > grille(2, vector<int>(nbCols, -1));
for(auto pt : pts)
{
int ligAct = pt.first;
int colAct = pt.second;
if(ligAct<1)
{
res += abs(1 - ligAct);
ligAct = 1;
}
if(ligAct>2)
{
res += abs(2 - ligAct);
ligAct = 2;
}
if(colAct<1)
{
res += abs(1 - colAct);
colAct = 1;
}
if(colAct>nbCols)
{
res += abs(nbCols - colAct);
colAct = nbCols;
}
ligAct--;
colAct--;
grille[ligAct][colAct]++;
}
for(int iC = 0; iC < nbCols; iC++)
{
if(iC >0)
{
grille[0][iC] += grille[0][iC-1];
grille[1][iC] += grille[1][iC-1];
}
if(grille[0][iC] * grille[1][iC] < 0)
{
int transferable = max(grille[0][iC], grille[1][iC]);
int needed = abs(min(grille[0][iC], grille[1][iC]));
int transfered = min(transferable, needed);
for(int iL=0; iL<2; iL++)
{
if(grille[iL][iC] < 0)
grille[iL][iC] += transfered;
else
grille[iL][iC] -= transfered;
}
res += transfered;
}
res += abs(grille[0][iC]);
res += abs(grille[1][iC]);
}
printf("%lld\n", res);
}
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... |