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>
using namespace std;
int nbIci[2][100000];
int main() {
int nbCols;
cin >> nbCols;
long long totalDist = 0;
for(int iPiece = 0;iPiece < 2 * nbCols;iPiece++) {
int col, lig;
cin >> col >> lig;
int ncol = max(1, min(nbCols, col));
int nlig = max(1, min(2, lig));
totalDist += abs(lig - nlig) + abs(col - ncol);
nbIci[nlig - 1][ncol - 1]++;
}
int resteBas = 0, resteHaut = 0;
for(int iPos = 0;iPos < nbCols;iPos++) {
resteBas += nbIci[0][iPos] - 1;
resteHaut += nbIci[1][iPos] - 1;
if(resteBas > 0 && resteHaut < 0) {
int transfert = min(resteBas, -resteHaut);
totalDist += transfert;
resteBas -= transfert;
resteHaut += transfert;
}
if(resteBas < 0 && resteHaut > 0) {
int transfert = min(-resteBas, resteHaut);
totalDist += transfert;
resteBas += transfert;
resteHaut -= transfert;
}
totalDist += abs(resteBas) + abs(resteHaut);
}
cout << totalDist << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |