a53

Meteoriti

a53
May 4th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <cstdio>
  2. #include <deque>
  3. using namespace std;
  4.  
  5. const char INFILE[] = "meteoriti.in";
  6. const char OUTFILE[] = "meteoriti.out";
  7.  
  8. const int NMAX = 2 * 1000 + 2;
  9. const int RMAX = 100 * 1000 + 2;
  10.  
  11. const int DIR[4][4] = {
  12. {-1, 0, 1, 0},
  13. {0, 1, 0, -1}
  14. };
  15.  
  16. int n, m, maxx, cnt, sol1, sol2;
  17. int mat[NMAX][NMAX];
  18. deque< pair<int, int> > deq;
  19.  
  20. void GetMax()
  21. {
  22. for (int j, i = 1; i <= n; ++i)
  23. for (j = 1; j <= m; ++j) {
  24. mat[i][j] += mat[i][j - 1];
  25. if (mat[i][j] > maxx)
  26. maxx = mat[i][j];
  27. }
  28.  
  29. for (int j, i = 1; i <= m; ++i)
  30. for (j = 1; j <= n; ++j) {
  31. mat[j][i] += mat[j - 1][i];
  32. if (mat[j][i] > maxx)
  33. maxx = mat[j][i];
  34. }
  35. }
  36.  
  37. inline void FillMat(int row, int col)
  38. {
  39. int new_row, new_col;
  40. deq.push_back(make_pair(row, col));
  41. mat[row][col] = -maxx;
  42.  
  43. while (!deq.empty()) {
  44. if (++cnt > sol1)
  45. sol1 = cnt;
  46.  
  47. row = deq.front().first;
  48. col = deq.front().second;
  49. for (int i = 0; i < 4; ++i) {
  50. new_row = row + DIR[0][i];
  51. new_col = col + DIR[1][i];
  52. if (new_row && new_col && new_row <= n && new_col <= m)
  53. if (mat[new_row][new_col] == maxx) {
  54. mat[new_row][new_col] = -maxx;
  55. deq.push_back(make_pair(new_row, new_col));
  56. }
  57. }
  58. deq.pop_front();
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. freopen(INFILE, "r", stdin);
  65. freopen(OUTFILE, "w", stdout);
  66.  
  67. int r, x1, y1,x2, y2, c;
  68. scanf("%d%d", &n, &m);
  69. for (scanf("%d", &r); r; --r) {
  70. scanf("%d%d", &x1, &y1);
  71. scanf("%d%d", &x2, &y2);
  72. scanf("%d", &c);
  73. mat[x1][y1] += c;
  74. mat[x1][y2 + 1] -= c;
  75. mat[x2 + 1][y1] -= c;
  76. mat[x2 + 1][y2 + 1] += c;
  77. }
  78.  
  79. GetMax();
  80.  
  81. for (int j, i = 1; i <= n; ++i)
  82. for (j = 1; j <= m; ++j)
  83. if (mat[i][j] == maxx) {
  84. cnt = 0;
  85. FillMat(i, j);
  86. }
  87. else if (!mat[i][j])
  88. ++sol2;
  89.  
  90. printf("%d %d", sol1, sol2);
  91.  
  92. return 0;
  93. }
Add Comment
Please, Sign In to add comment