Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int nbCols, nbLignes;
- int grille[500][500];
- int plusMax[500][500];
- const int dirs[4][2] = { {0, 1}, {1, 0}, {-1, 0}, {0, -1} };
- const int INF = 2000000000;
- bool estBord(int i, int j)
- {
- return (i == 0 || i == nbLignes-1 || j == 0 || j == nbCols-1);
- }
- int main()
- {
- scanf("%d%d", &nbCols, &nbLignes);
- for(int i = 0; i < nbLignes; i++)
- {
- for(int j = 0; j < nbCols; j++)
- {
- scanf("%d", &grille[i][j]);
- plusMax[i][j] = INF;
- if(estBord(i, j)) //bords
- plusMax[i][j] = grille[i][j];
- }
- }
- for(int k = 0; k < 30; k++) //hum, + ou - ? on va mettre un grand truc pour pas de pb et que ça passe ><
- for(int i = 0; i < nbLignes; i++)
- {
- for(int j = 0; j < nbCols; j++)
- {
- if(estBord(i, j))
- continue;
- int valBordMin = INF;
- for(int d = 0; d < 4; d++)
- {
- int x = j + dirs[d][0];
- int y = i + dirs[d][1];
- if(x >= 0 && x < nbCols && y >= 0 && y < nbLignes)
- valBordMin = min(valBordMin, plusMax[y][x]);
- }
- plusMax[i][j] = std::max(grille[i][j], valBordMin);
- }
- }
- int total = 0;
- for(int i = 0; i < nbLignes; i++)
- for(int j = 0; j < nbCols; j++)
- total+=plusMax[i][j]-grille[i][j];
- printf("%d\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment