Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <queue>
  2. #include <bitset>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. class InputReader
  8. {
  9. public:
  10. static const int BUFF_SIZE = 1 << 17;
  11. FILE *fin;
  12. int bp;
  13. char buff[BUFF_SIZE];
  14. InputReader (const char *file_name)
  15. {
  16. fin = fopen(file_name, "r");
  17. bp = BUFF_SIZE - 1;
  18. }
  19. void adv()
  20. {
  21. if (++bp == BUFF_SIZE)
  22. {
  23. fread(buff, sizeof(char), BUFF_SIZE, fin);
  24. bp = 0;
  25. }
  26. }
  27. InputReader& operator >> (int& num)
  28. {
  29. num = 0;
  30. while (isdigit(buff[bp]) == false)
  31. adv();
  32. while (isdigit(buff[bp]))
  33. {
  34. num = num * 10 + buff[bp] - '0';
  35. adv();
  36. }
  37. return *this;
  38. }
  39. };
  40.  
  41. InputReader fin("sahara.in");
  42. ofstream fout("sahara.out");
  43.  
  44. const int MAXN = 1005;
  45.  
  46. int mat[MAXN][MAXN];
  47. int n, m, a, q;
  48.  
  49. int di[] = {0, 0, -1, 1};
  50. int dj[] = {-1, 1, 0, 0};
  51.  
  52. queue < pair < int, int > > Q;
  53. bitset < MAXN > um[MAXN];
  54.  
  55. inline bool valid(int i, int j)
  56. {
  57. return (i >= 1 && i <= n && j >= 1 && j <= m && !um[i][j]);
  58. }
  59.  
  60. void ump(int A, int B)
  61. {
  62. Q.push(make_pair(A, B));
  63. while (!Q.empty())
  64. {
  65. int i = Q.front().first;
  66. int j = Q.front().second;
  67. Q.pop();
  68. for (int k = 0; k < 4; ++k)
  69. {
  70. int inou = i + di[k];
  71. int jnou = j + dj[k];
  72. if (valid(inou, jnou) && mat[inou][jnou] >= q)
  73. {
  74. ++a;
  75. um[inou][jnou] = 1;
  76. Q.push(make_pair(inou, jnou));
  77. }
  78. }
  79. }
  80. }
  81.  
  82. int main()
  83. {
  84. int t, l1, l2, c1, c2, x, i, j, amax = 0;
  85. fin >> n >> m >> q >> t;
  86. while (t--)
  87. {
  88. fin >> l1 >> c1 >> l2 >> c2 >> x;
  89. mat[l1][c1] += x;
  90. mat[l2 + 1][c2 + 1] += x;
  91. mat[l2 + 1][c1] -= x;
  92. mat[l1][c2 + 1] -= x;
  93. }
  94. for (i = 1; i <= n; ++i)
  95. {
  96. for (j = 1; j <= m; ++j)
  97. {
  98. mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
  99. }
  100. }
  101. for (i = 1; i <= n; ++i)
  102. {
  103. for (j = 1; j <= m; ++j)
  104. {
  105. if (!um[i][j] && mat[i][j] >= q)
  106. {
  107. a = 0;
  108. ump(i, j);
  109. if (a > amax) amax = a;
  110. }
  111. }
  112. }
  113. fout << amax << '\n';
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement