Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- long unsigned int sum = 0;
- unsigned int rows, cols, days, rott_row, rott_col, rott_per_day = 0, rott_previous = 0;
- cin >> rows >> cols >> days;
- vector<vector<unsigned int>> grid(rows+1, vector<unsigned int>(cols+1));
- sum = rows*cols;
- queue <pair< unsigned int, unsigned int>> gps;
- while (cin >> rott_row >> rott_col) {
- grid[rott_row][rott_col] = 1;
- gps.push({ rott_row, rott_col });
- rott_per_day++;
- sum--;
- }
- for (unsigned int i = 0; i < days; i++)
- {
- rott_previous = rott_per_day;
- rott_per_day = 0;
- for (unsigned int j = 0; j < rott_previous; j++)
- {
- pair<unsigned int, unsigned int> cord = gps.front();
- unsigned int x = cord.first;
- unsigned int y = cord.second;
- if (x - 1 > 0 && grid[x - 1][y] != 1) // Take the apple above the rotten (if there is one)
- {
- grid[x - 1][y] = 1;
- sum--;
- gps.push({ x-1, y });
- rott_per_day++;
- }
- if (x + 1 <= rows && grid[x + 1][y] != 1) // Take the apple under the rotten (if there is one)
- {
- grid[x + 1][y] = 1;
- sum--;
- gps.push({ x+1, y });
- rott_per_day++;
- }
- if (y - 1 > 0 && grid[x][y - 1] != 1) // Take the apple left the rotten (if there is one)
- {
- grid[x][y - 1] = 1;
- sum--;
- gps.push({ x, y-1 });
- rott_per_day++;
- }
- if (y + 1 <= cols && grid[x][y + 1] != 1) // Take the apple right the rotten (if there is one)
- {
- grid[x][y + 1] = 1;
- sum--;
- gps.push({ x, y +1});
- rott_per_day++;
- }
- gps.pop();
- }
- }
- cout << sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement