Submission #71895

#TimeUsernameProblemLanguageResultExecution timeMemory
71895AdrienVannsonCultivation (JOI17_cultivation)C++14
15 / 100
2062 ms756 KiB
// Sous-tâche 1, 2, 3 (et plus ?) #include <algorithm> #include <algorithm> #include <iostream> #include <cstdio> #include <array> #include <vector> #include <map> #include <set> using namespace std; #define ll long long const int oo = 2*1000*1000*1000 + 42; const int NB_MAX_CELLULES_PLEINES = 300; const int NB_MAX_LIGNES = 1000*1000*1000 + 1; const int NB_MAX_COLONNES = 1000*1000*1000 + 1; const int NB_MAX_INDEXS = 3*NB_MAX_CELLULES_PLEINES; int nbLignes, nbColonnes; int nbCellulesPleines; pair<int, int> cellulesPleines[NB_MAX_CELLULES_PLEINES]; bool getEstPossible (const ll nbBas, const ll nbDroite) { struct Evenement { bool estDebut; ll iColonne; ll iLigneDebut, iLigneFin; bool operator< (const Evenement &autre) const { if (iColonne != autre.iColonne) { return iColonne < autre.iColonne; } if (estDebut != autre.estDebut) { return estDebut; } if (iLigneDebut != autre.iLigneDebut) { return iLigneDebut < autre.iLigneDebut; } return iLigneFin < autre.iLigneFin; } }; set<ll> indexs; vector<Evenement> evenements; for (int iCellulePleine=0; iCellulePleine<nbCellulesPleines; iCellulePleine++) { const ll iLigne = cellulesPleines[iCellulePleine].first; const ll iColonne = cellulesPleines[iCellulePleine].second; evenements.push_back(Evenement{true, iColonne, iLigne, iLigne+nbBas+1}); evenements.push_back(Evenement{false, iColonne+nbDroite+1, iLigne, iLigne+nbBas+1}); indexs.insert(iLigne); indexs.insert(iLigne+nbBas+1); if (iLigne > 0) { indexs.insert(iLigne-1); } } // Réindexation map<ll, int> reindexation; int nouvelIndex = 0; for (ll index : indexs) { reindexation[index] = nouvelIndex; nouvelIndex++; } sort(evenements.begin(), evenements.end()); int nbRecouvrements[NB_MAX_INDEXS]; fill(nbRecouvrements, nbRecouvrements+NB_MAX_INDEXS, 0); int dernierPlein[NB_MAX_INDEXS]; fill(dernierPlein, dernierPlein+NB_MAX_INDEXS, +oo); for (const Evenement &evenement : evenements) { const int iColonne = evenement.iColonne; // Vérification de la validité if (!evenement.estDebut) { ll iLigneInvalide = -1; bool dernierValide = false; for (ll iLigne : indexs) { const int index = reindexation[iLigne]; if (dernierValide && iLigne-iLigneInvalide-1 >= nbLignes) { return true; } if (iColonne - dernierPlein[index] < nbColonnes) { // Invalide iLigneInvalide = iLigne; dernierValide = false; } else { dernierValide = true; } if (iLigne - iLigneInvalide >= nbLignes) { return true; } } } // Mise à jour for (int iLigne=reindexation[evenement.iLigneDebut]; iLigne<reindexation[evenement.iLigneFin]; iLigne++) { nbRecouvrements[iLigne] += evenement.estDebut ? 1 : -1; if (nbRecouvrements[iLigne] == 0) { dernierPlein[iLigne] = +oo; } else if (dernierPlein[iLigne] == +oo) { dernierPlein[iLigne] = iColonne; } } } return false; } int main () { scanf("%d %d", &nbLignes, &nbColonnes); scanf("%d", &nbCellulesPleines); for (int iCellule=0; iCellule<nbCellulesPleines; iCellule++) { int iLigne, iColonne; scanf("%d %d", &iLigne, &iColonne); iLigne--, iColonne--; cellulesPleines[iCellule] = make_pair(iLigne, iColonne); } ll nbEtapesMin = +oo; ll nbBas = 0; ll nbDroite = 2*NB_MAX_COLONNES; while (true) { ll nbBasAvant = nbBas; ll nbDroiteAvant = nbDroite; // Augmenter nbBas ll debut = -1; ll fin = 2*NB_MAX_LIGNES; while (fin-debut > 1) { const ll milieu = (debut + fin) / 2; if (getEstPossible(milieu, nbDroite-1)) { fin = milieu; } else { debut = milieu; } } nbBas = fin; // Diminuer nbDroite debut = -1; fin = 2*NB_MAX_COLONNES; while (fin-debut > 1) { const ll milieu = (debut + fin) / 2; if (getEstPossible(nbBas, milieu)) { fin = milieu; } else { debut = milieu; } } nbDroite = fin; nbEtapesMin = min(nbBas+nbDroite, nbEtapesMin); if ((nbBas == nbBasAvant && nbDroite == nbDroiteAvant) || nbDroite == 0) { break; } } printf("%lld\n", nbEtapesMin); return 0; }

Compilation message (stderr)

cultivation.cpp: In function 'int main()':
cultivation.cpp:141:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &nbLignes, &nbColonnes);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:142:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &nbCellulesPleines);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:146:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &iLigne, &iColonne);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...