// Sous-tâche 1, 2 & 3
#include <algorithm>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <array>
#include <vector>
using namespace std;
const int oo = 1000*1000*1000;
const int NB_MAX_CELLULES_PLEINES = 300;
const int TAILLE_MAX_GRILLE_DEPART = 2*40;
const int NB_MAX_LIGNES = 2 * TAILLE_MAX_GRILLE_DEPART;
const int NB_MAX_COLONNES = 1000*1000*1000 + 1;
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;
}
};
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});
}
sort(evenements.begin(), evenements.end());
int nbRecouvrements[NB_MAX_LIGNES];
fill(nbRecouvrements, nbRecouvrements+NB_MAX_LIGNES, 0);
int dernierPlein[NB_MAX_LIGNES];
fill(dernierPlein, dernierPlein+NB_MAX_LIGNES, +oo);
for (const Evenement &evenement : evenements) {
const int iColonne = evenement.iColonne;
// Vérification de la validité
if (!evenement.estDebut) {
int iLigneInvalide = -1;
for (int iLigne=0; iLigne<NB_MAX_LIGNES; iLigne++) {
if (iColonne - dernierPlein[iLigne] < nbColonnes) { // Invalide
iLigneInvalide = iLigne;
}
if (iLigne - iLigneInvalide >= nbLignes) {
return true;
}
}
}
// Mise à jour
for (int iLigne=evenement.iLigneDebut; iLigne<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);
if (nbLignes > 40) {
exit(42);
}
for (int iCellule=0; iCellule<nbCellulesPleines; iCellule++) {
int iLigne, iColonne;
scanf("%d %d", &iLigne, &iColonne);
iLigne--, iColonne--;
cellulesPleines[iCellule] = make_pair(iLigne, iColonne);
}
int nbEtapesMin = +oo;
for (int nbEtapesBas=0; nbEtapesBas<TAILLE_MAX_GRILLE_DEPART; nbEtapesBas++) {
if (getEstPossible(nbEtapesBas, 0)) {
nbEtapesMin = min(nbEtapesBas, nbEtapesMin);
continue;
}
int debut = 0;
int fin = 2*NB_MAX_COLONNES;
while (fin-debut > 1) {
const int milieu = (debut + fin) / 2;
if (getEstPossible(nbEtapesBas, milieu)) {
fin = milieu;
}
else {
debut = milieu;
}
}
if (fin < 2*NB_MAX_COLONNES) {
nbEtapesMin = min(nbEtapesBas+fin, nbEtapesMin);
}
}
printf("%d\n", nbEtapesMin);
return 0;
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:108: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:109:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &nbCellulesPleines);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:117:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &iLigne, &iColonne);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
4 ms |
388 KB |
Output is correct |
4 |
Correct |
4 ms |
388 KB |
Output is correct |
5 |
Correct |
3 ms |
480 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
540 KB |
Output is correct |
11 |
Correct |
4 ms |
540 KB |
Output is correct |
12 |
Correct |
4 ms |
540 KB |
Output is correct |
13 |
Correct |
4 ms |
540 KB |
Output is correct |
14 |
Correct |
4 ms |
540 KB |
Output is correct |
15 |
Correct |
4 ms |
540 KB |
Output is correct |
16 |
Correct |
5 ms |
540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
4 ms |
388 KB |
Output is correct |
4 |
Correct |
4 ms |
388 KB |
Output is correct |
5 |
Correct |
3 ms |
480 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
540 KB |
Output is correct |
11 |
Correct |
4 ms |
540 KB |
Output is correct |
12 |
Correct |
4 ms |
540 KB |
Output is correct |
13 |
Correct |
4 ms |
540 KB |
Output is correct |
14 |
Correct |
4 ms |
540 KB |
Output is correct |
15 |
Correct |
4 ms |
540 KB |
Output is correct |
16 |
Correct |
5 ms |
540 KB |
Output is correct |
17 |
Correct |
13 ms |
540 KB |
Output is correct |
18 |
Correct |
34 ms |
540 KB |
Output is correct |
19 |
Correct |
17 ms |
540 KB |
Output is correct |
20 |
Correct |
14 ms |
628 KB |
Output is correct |
21 |
Correct |
28 ms |
628 KB |
Output is correct |
22 |
Correct |
70 ms |
628 KB |
Output is correct |
23 |
Correct |
25 ms |
628 KB |
Output is correct |
24 |
Correct |
78 ms |
636 KB |
Output is correct |
25 |
Correct |
81 ms |
636 KB |
Output is correct |
26 |
Correct |
135 ms |
648 KB |
Output is correct |
27 |
Correct |
105 ms |
764 KB |
Output is correct |
28 |
Correct |
123 ms |
764 KB |
Output is correct |
29 |
Correct |
81 ms |
764 KB |
Output is correct |
30 |
Correct |
100 ms |
764 KB |
Output is correct |
31 |
Correct |
141 ms |
764 KB |
Output is correct |
32 |
Correct |
97 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
4 ms |
388 KB |
Output is correct |
4 |
Correct |
4 ms |
388 KB |
Output is correct |
5 |
Correct |
3 ms |
480 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
540 KB |
Output is correct |
11 |
Correct |
4 ms |
540 KB |
Output is correct |
12 |
Correct |
4 ms |
540 KB |
Output is correct |
13 |
Correct |
4 ms |
540 KB |
Output is correct |
14 |
Correct |
4 ms |
540 KB |
Output is correct |
15 |
Correct |
4 ms |
540 KB |
Output is correct |
16 |
Correct |
5 ms |
540 KB |
Output is correct |
17 |
Correct |
13 ms |
540 KB |
Output is correct |
18 |
Correct |
34 ms |
540 KB |
Output is correct |
19 |
Correct |
17 ms |
540 KB |
Output is correct |
20 |
Correct |
14 ms |
628 KB |
Output is correct |
21 |
Correct |
28 ms |
628 KB |
Output is correct |
22 |
Correct |
70 ms |
628 KB |
Output is correct |
23 |
Correct |
25 ms |
628 KB |
Output is correct |
24 |
Correct |
78 ms |
636 KB |
Output is correct |
25 |
Correct |
81 ms |
636 KB |
Output is correct |
26 |
Correct |
135 ms |
648 KB |
Output is correct |
27 |
Correct |
105 ms |
764 KB |
Output is correct |
28 |
Correct |
123 ms |
764 KB |
Output is correct |
29 |
Correct |
81 ms |
764 KB |
Output is correct |
30 |
Correct |
100 ms |
764 KB |
Output is correct |
31 |
Correct |
141 ms |
764 KB |
Output is correct |
32 |
Correct |
97 ms |
764 KB |
Output is correct |
33 |
Correct |
304 ms |
764 KB |
Output is correct |
34 |
Correct |
199 ms |
888 KB |
Output is correct |
35 |
Correct |
364 ms |
888 KB |
Output is correct |
36 |
Correct |
339 ms |
888 KB |
Output is correct |
37 |
Correct |
373 ms |
888 KB |
Output is correct |
38 |
Correct |
341 ms |
888 KB |
Output is correct |
39 |
Correct |
334 ms |
888 KB |
Output is correct |
40 |
Correct |
327 ms |
888 KB |
Output is correct |
41 |
Correct |
289 ms |
888 KB |
Output is correct |
42 |
Correct |
296 ms |
892 KB |
Output is correct |
43 |
Correct |
372 ms |
892 KB |
Output is correct |
44 |
Correct |
403 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
4 ms |
388 KB |
Output is correct |
4 |
Correct |
4 ms |
388 KB |
Output is correct |
5 |
Correct |
3 ms |
480 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
540 KB |
Output is correct |
11 |
Correct |
4 ms |
540 KB |
Output is correct |
12 |
Correct |
4 ms |
540 KB |
Output is correct |
13 |
Correct |
4 ms |
540 KB |
Output is correct |
14 |
Correct |
4 ms |
540 KB |
Output is correct |
15 |
Correct |
4 ms |
540 KB |
Output is correct |
16 |
Correct |
5 ms |
540 KB |
Output is correct |
17 |
Correct |
13 ms |
540 KB |
Output is correct |
18 |
Correct |
34 ms |
540 KB |
Output is correct |
19 |
Correct |
17 ms |
540 KB |
Output is correct |
20 |
Correct |
14 ms |
628 KB |
Output is correct |
21 |
Correct |
28 ms |
628 KB |
Output is correct |
22 |
Correct |
70 ms |
628 KB |
Output is correct |
23 |
Correct |
25 ms |
628 KB |
Output is correct |
24 |
Correct |
78 ms |
636 KB |
Output is correct |
25 |
Correct |
81 ms |
636 KB |
Output is correct |
26 |
Correct |
135 ms |
648 KB |
Output is correct |
27 |
Correct |
105 ms |
764 KB |
Output is correct |
28 |
Correct |
123 ms |
764 KB |
Output is correct |
29 |
Correct |
81 ms |
764 KB |
Output is correct |
30 |
Correct |
100 ms |
764 KB |
Output is correct |
31 |
Correct |
141 ms |
764 KB |
Output is correct |
32 |
Correct |
97 ms |
764 KB |
Output is correct |
33 |
Correct |
304 ms |
764 KB |
Output is correct |
34 |
Correct |
199 ms |
888 KB |
Output is correct |
35 |
Correct |
364 ms |
888 KB |
Output is correct |
36 |
Correct |
339 ms |
888 KB |
Output is correct |
37 |
Correct |
373 ms |
888 KB |
Output is correct |
38 |
Correct |
341 ms |
888 KB |
Output is correct |
39 |
Correct |
334 ms |
888 KB |
Output is correct |
40 |
Correct |
327 ms |
888 KB |
Output is correct |
41 |
Correct |
289 ms |
888 KB |
Output is correct |
42 |
Correct |
296 ms |
892 KB |
Output is correct |
43 |
Correct |
372 ms |
892 KB |
Output is correct |
44 |
Correct |
403 ms |
900 KB |
Output is correct |
45 |
Runtime error |
2 ms |
900 KB |
Execution failed because the return code was nonzero |
46 |
Halted |
0 ms |
0 KB |
- |