Submission #943763

#TimeUsernameProblemLanguageResultExecution timeMemory
943763tsetCoin Collecting (JOI19_ho_t4)C++17
100 / 100
47 ms10400 KiB
#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)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:8:9: warning: unused variable 'nbLigs' [-Wunused-variable]
    8 |     int nbLigs = 2,nbCols;
      |         ^~~~~~
joi2019_ho_t4.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%lld", &nbCols);
      |     ~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld%lld", &col, &lig);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...