Advertisement
monito2207

Winter in Rodopi mountain

Nov 22nd, 2024
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <queue>
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(nullptr);
  13.     long unsigned int sum = 0;
  14.     unsigned int rows, cols, days, rott_row, rott_col, rott_per_day = 0, rott_previous = 0;
  15.     cin >> rows >> cols >> days;
  16.     vector<vector<unsigned int>> grid(rows+1, vector<unsigned int>(cols+1));
  17.     sum = rows*cols;
  18.     queue <pair< unsigned int, unsigned int>> gps;
  19.     while (cin >> rott_row >> rott_col) {
  20.         grid[rott_row][rott_col] = 1;
  21.         gps.push({ rott_row, rott_col });
  22.         rott_per_day++;
  23.         sum--;
  24.     }
  25.  
  26.     for (unsigned int i = 0; i < days; i++)
  27.     {
  28.         rott_previous = rott_per_day;
  29.         rott_per_day = 0;
  30.         for (unsigned int j = 0; j < rott_previous; j++)
  31.         {
  32.             pair<unsigned int, unsigned int> cord = gps.front();
  33.             unsigned int x = cord.first;
  34.             unsigned int y = cord.second;
  35.             if (x - 1 > 0 && grid[x - 1][y] != 1)         // Take the apple above the rotten (if there is one)
  36.             {
  37.                 grid[x - 1][y] = 1;
  38.                 sum--;
  39.                 gps.push({ x-1, y });
  40.                 rott_per_day++;
  41.             }
  42.             if (x + 1 <= rows && grid[x + 1][y] != 1)         // Take the apple under the rotten (if there is one)
  43.             {
  44.                 grid[x + 1][y] = 1;
  45.                 sum--;
  46.                 gps.push({ x+1, y });
  47.                 rott_per_day++;
  48.             }
  49.             if (y - 1 > 0 && grid[x][y - 1] != 1)         // Take the apple left the rotten (if there is one)
  50.             {
  51.                 grid[x][y - 1] = 1;
  52.                 sum--;
  53.                 gps.push({ x, y-1 });
  54.                 rott_per_day++;
  55.             }
  56.             if (y + 1 <= cols && grid[x][y + 1] != 1)         // Take the apple right the rotten (if there is one)
  57.             {
  58.                 grid[x][y + 1] = 1;
  59.                 sum--;
  60.                 gps.push({ x, y +1});
  61.                 rott_per_day++;
  62.             }
  63.             gps.pop();
  64.         }
  65.        
  66.     }
  67.     cout << sum;
  68.     return 0;
  69. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement