Submission #71890

# Submission time Handle Problem Language Result Execution time Memory
71890 2018-08-25T18:46:15 Z AdrienVannson Cultivation (JOI17_cultivation) C++14
15 / 100
2000 ms 904 KB
// Sous-tâche 1, 2, 3 (et plus ?)

#include <algorithm>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <array>
#include <vector>
#include <map>
#include <set>

#define int long long

using namespace std;

const int oo = 2*1000*1000*1000 + 42;

const int NB_MAX_CELLULES_PLEINES = 300;

const int NB_MAX_LIGNES = (int)2*1000*1000*1000+1;
const int NB_MAX_COLONNES = (int)2*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 int nbBas, const int nbDroite)
{
    struct Evenement
    {
        bool estDebut;
        int iColonne;
        int 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<int> indexs;
    vector<Evenement> evenements;

    for (int iCellulePleine=0; iCellulePleine<nbCellulesPleines; iCellulePleine++) {
        const int iLigne = cellulesPleines[iCellulePleine].first;
        const int 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<int, int> reindexation;

    int nouvelIndex = 0;
    for (int 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) {

            int iLigneInvalide = -1;
            bool dernierValide = false;

            for (int 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;
}


int32_t main ()
{
    scanf("%lld %lld", &nbLignes, &nbColonnes);
    scanf("%lld", &nbCellulesPleines);

    for (int iCellule=0; iCellule<nbCellulesPleines; iCellule++) {
        int iLigne, iColonne;
        scanf("%lld %lld", &iLigne, &iColonne);
        iLigne--, iColonne--;

        cellulesPleines[iCellule] = make_pair(iLigne, iColonne);
    }

    /*cerr << getEstPossible(3, 3) << endl;
    return 0;*/

    int nbEtapesMin = +oo;
    int nbBas = 0;
    int nbDroite = NB_MAX_COLONNES;

    while (true) {

        int nbBasAvant = nbBas;
        int nbDroiteAvant = nbDroite;

        // Augmenter nbBas
        int debut = -1;
        int fin = NB_MAX_LIGNES;

        while (fin-debut > 1) {
            const int milieu = (debut + fin) / 2;

            if (getEstPossible(milieu, nbDroite-1)) {
                fin = milieu;
            }
            else {
                debut = milieu;
            }
        }
        nbBas = fin;

        // Diminuer nbDroite
        debut = -1;
        fin = NB_MAX_COLONNES;

        while (fin-debut > 1) {
            const int 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

cultivation.cpp: In function 'int32_t main()':
cultivation.cpp:141:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld", &nbLignes, &nbColonnes);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:142:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &nbCellulesPleines);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:146:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &iLigne, &iColonne);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 4 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 4 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 4 ms 712 KB Output is correct
14 Correct 3 ms 712 KB Output is correct
15 Correct 4 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 4 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 4 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 4 ms 712 KB Output is correct
14 Correct 3 ms 712 KB Output is correct
15 Correct 4 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 14 ms 712 KB Output is correct
18 Correct 41 ms 712 KB Output is correct
19 Correct 36 ms 712 KB Output is correct
20 Correct 10 ms 712 KB Output is correct
21 Correct 165 ms 748 KB Output is correct
22 Correct 195 ms 748 KB Output is correct
23 Correct 18 ms 748 KB Output is correct
24 Correct 220 ms 748 KB Output is correct
25 Correct 196 ms 748 KB Output is correct
26 Correct 434 ms 748 KB Output is correct
27 Correct 369 ms 748 KB Output is correct
28 Correct 310 ms 748 KB Output is correct
29 Correct 277 ms 748 KB Output is correct
30 Correct 253 ms 748 KB Output is correct
31 Correct 237 ms 748 KB Output is correct
32 Correct 324 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 4 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 4 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 4 ms 712 KB Output is correct
14 Correct 3 ms 712 KB Output is correct
15 Correct 4 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 14 ms 712 KB Output is correct
18 Correct 41 ms 712 KB Output is correct
19 Correct 36 ms 712 KB Output is correct
20 Correct 10 ms 712 KB Output is correct
21 Correct 165 ms 748 KB Output is correct
22 Correct 195 ms 748 KB Output is correct
23 Correct 18 ms 748 KB Output is correct
24 Correct 220 ms 748 KB Output is correct
25 Correct 196 ms 748 KB Output is correct
26 Correct 434 ms 748 KB Output is correct
27 Correct 369 ms 748 KB Output is correct
28 Correct 310 ms 748 KB Output is correct
29 Correct 277 ms 748 KB Output is correct
30 Correct 253 ms 748 KB Output is correct
31 Correct 237 ms 748 KB Output is correct
32 Correct 324 ms 748 KB Output is correct
33 Correct 25 ms 748 KB Output is correct
34 Execution timed out 2058 ms 748 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 748 KB Output is correct
2 Correct 108 ms 748 KB Output is correct
3 Correct 113 ms 748 KB Output is correct
4 Correct 739 ms 748 KB Output is correct
5 Correct 117 ms 748 KB Output is correct
6 Correct 68 ms 748 KB Output is correct
7 Correct 36 ms 748 KB Output is correct
8 Correct 375 ms 824 KB Output is correct
9 Correct 62 ms 824 KB Output is correct
10 Correct 156 ms 880 KB Output is correct
11 Correct 82 ms 880 KB Output is correct
12 Correct 106 ms 880 KB Output is correct
13 Correct 11 ms 880 KB Output is correct
14 Correct 56 ms 896 KB Output is correct
15 Correct 78 ms 896 KB Output is correct
16 Correct 92 ms 904 KB Output is correct
17 Correct 92 ms 904 KB Output is correct
18 Correct 89 ms 904 KB Output is correct
19 Correct 94 ms 904 KB Output is correct
20 Execution timed out 2067 ms 904 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 54 ms 748 KB Output is correct
2 Correct 108 ms 748 KB Output is correct
3 Correct 113 ms 748 KB Output is correct
4 Correct 739 ms 748 KB Output is correct
5 Correct 117 ms 748 KB Output is correct
6 Correct 68 ms 748 KB Output is correct
7 Correct 36 ms 748 KB Output is correct
8 Correct 375 ms 824 KB Output is correct
9 Correct 62 ms 824 KB Output is correct
10 Correct 156 ms 880 KB Output is correct
11 Correct 82 ms 880 KB Output is correct
12 Correct 106 ms 880 KB Output is correct
13 Correct 11 ms 880 KB Output is correct
14 Correct 56 ms 896 KB Output is correct
15 Correct 78 ms 896 KB Output is correct
16 Correct 92 ms 904 KB Output is correct
17 Correct 92 ms 904 KB Output is correct
18 Correct 89 ms 904 KB Output is correct
19 Correct 94 ms 904 KB Output is correct
20 Execution timed out 2067 ms 904 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 4 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 4 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 4 ms 712 KB Output is correct
14 Correct 3 ms 712 KB Output is correct
15 Correct 4 ms 712 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 14 ms 712 KB Output is correct
18 Correct 41 ms 712 KB Output is correct
19 Correct 36 ms 712 KB Output is correct
20 Correct 10 ms 712 KB Output is correct
21 Correct 165 ms 748 KB Output is correct
22 Correct 195 ms 748 KB Output is correct
23 Correct 18 ms 748 KB Output is correct
24 Correct 220 ms 748 KB Output is correct
25 Correct 196 ms 748 KB Output is correct
26 Correct 434 ms 748 KB Output is correct
27 Correct 369 ms 748 KB Output is correct
28 Correct 310 ms 748 KB Output is correct
29 Correct 277 ms 748 KB Output is correct
30 Correct 253 ms 748 KB Output is correct
31 Correct 237 ms 748 KB Output is correct
32 Correct 324 ms 748 KB Output is correct
33 Correct 25 ms 748 KB Output is correct
34 Execution timed out 2058 ms 748 KB Time limit exceeded
35 Halted 0 ms 0 KB -