Advertisement
MathQ_

Untitled

Oct 18th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <vector>
  7. #include <stack>
  8. #include <deque>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <stack>
  13. #include <string>
  14. #include <random>
  15. #include <numeric>
  16. #include <unordered_set>
  17.  
  18. typedef long long ll;
  19. typedef long double lb;
  20.  
  21. #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  22. #define file_in freopen("input.txt", "r", stdin);
  23. #define file_in_out freopen("inverse.in", "r", stdin); freopen("inverse.out", "w", stdout);
  24. #define mp make_pair
  25. #define all(x) (x).begin(), (x).end()
  26. #define fi first
  27. #define se second
  28.  
  29. using namespace std;
  30.  
  31. template<typename T>
  32. istream& operator>>(istream &in, vector<T> &v) {
  33. for (auto &it : v) {
  34. in >> it;
  35. }
  36. return in;
  37. }
  38.  
  39. template<typename T>
  40. ostream& operator<<(ostream &out, vector<T> &v) {
  41. if (!v.empty()) {
  42. out << v.front();
  43. for (int i = 1; i < v.size(); ++i) {
  44. out << " " << v[i];
  45. }
  46. }
  47. return out;
  48. }
  49.  
  50. int main()
  51. {
  52. fast
  53. // file_in
  54. // file_in_out
  55.  
  56. int n, m;
  57. cin >> n >> m;
  58.  
  59. int dp[n][m];
  60. for (int i = 0; i < n; ++i) {
  61. for (int j = 0; j < m; ++j) {
  62. dp[i][j] = -1;
  63. }
  64. }
  65.  
  66. int x, y;
  67. cin >> x >> y;
  68. --x; --y;
  69.  
  70. int p = 0, count1 = 0, count2 = 0;
  71. while (x != -2 && y != -2) {
  72. if (dp[x][y] != p) {
  73. if (dp[x][y] != -1) {
  74. p ? --count1 : --count2;
  75. }
  76. p ? ++count2 : ++count1;
  77. }
  78. dp[x][y] = p;
  79.  
  80. // Обработка столбца y
  81. int first = x, last = x;
  82. for (int i = 0; i < n; ++i) {
  83. if (dp[i][y] == p) {
  84. if (i < x) {
  85. first = i;
  86. } else if (i > x) {
  87. last = i;
  88. break;
  89. }
  90. }
  91. }
  92. for (int i = first + 1; i <= last - 1; ++i) {
  93. if (dp[i][y] != p) {
  94. if (dp[i][y] != -1) {
  95. p ? --count1 : --count2;
  96. }
  97. p ? ++count2 : ++count1;
  98. dp[i][y] = p;
  99. }
  100. }
  101. // Обработка строки x
  102. first = y, last = y;
  103. for (int j = 0; j < m; ++j) {
  104. if (dp[x][j] == p) {
  105. if (j < y) {
  106. first = j;
  107. } else if (j > y) {
  108. last = j;
  109. break;
  110. }
  111. }
  112. }
  113. for (int j = first + 1; j <= last - 1; ++j) {
  114. if (dp[x][j] != p) {
  115. if (dp[x][j] != -1) {
  116. p ? --count1 : --count2;
  117. }
  118. p ? ++count2 : ++count1;
  119. dp[x][j] = p;
  120. }
  121. }
  122. cout << count1 - count2 << endl;
  123. cin >> x >> y;
  124. --x; --y;
  125. p = (p + 1) % 2;
  126. }
  127.  
  128. return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement