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 somme = 0;
for(int iPos = 0;iPos < nbCols;iPos++) {
somme += nbIci[0][iPos];
somme += nbIci[1][iPos];
totalDist += abs(somme - 2 * (iPos + 1));
}
somme = 0;
for(int iPos = 0;iPos < nbCols;iPos++) {
somme += nbIci[0][iPos];
}
totalDist += abs(somme - nbCols);
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... |