Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <stack>
- #include <deque>
- #include <queue>
- #include <set>
- #include <map>
- #include <stack>
- #include <string>
- #include <random>
- #include <numeric>
- #include <unordered_set>
- typedef long long ll;
- typedef long double lb;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define file_in_out freopen("inverse.in", "r", stdin); freopen("inverse.out", "w", stdout);
- #define mp make_pair
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- using namespace std;
- template<typename T>
- istream& operator>>(istream &in, vector<T> &v) {
- for (auto &it : v) {
- in >> it;
- }
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, vector<T> &v) {
- if (!v.empty()) {
- out << v.front();
- for (int i = 1; i < v.size(); ++i) {
- out << " " << v[i];
- }
- }
- return out;
- }
- int main()
- {
- fast
- // file_in
- // file_in_out
- int n, m;
- cin >> n >> m;
- int dp[n][m];
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- dp[i][j] = -1;
- }
- }
- int x, y;
- cin >> x >> y;
- --x; --y;
- int p = 0, count1 = 0, count2 = 0;
- while (x != -2 && y != -2) {
- if (dp[x][y] != p) {
- if (dp[x][y] != -1) {
- p ? --count1 : --count2;
- }
- p ? ++count2 : ++count1;
- }
- dp[x][y] = p;
- // Обработка столбца y
- int first = x, last = x;
- for (int i = 0; i < n; ++i) {
- if (dp[i][y] == p) {
- if (i < x) {
- first = i;
- } else if (i > x) {
- last = i;
- break;
- }
- }
- }
- for (int i = first + 1; i <= last - 1; ++i) {
- if (dp[i][y] != p) {
- if (dp[i][y] != -1) {
- p ? --count1 : --count2;
- }
- p ? ++count2 : ++count1;
- dp[i][y] = p;
- }
- }
- // Обработка строки x
- first = y, last = y;
- for (int j = 0; j < m; ++j) {
- if (dp[x][j] == p) {
- if (j < y) {
- first = j;
- } else if (j > y) {
- last = j;
- break;
- }
- }
- }
- for (int j = first + 1; j <= last - 1; ++j) {
- if (dp[x][j] != p) {
- if (dp[x][j] != -1) {
- p ? --count1 : --count2;
- }
- p ? ++count2 : ++count1;
- dp[x][j] = p;
- }
- }
- cout << count1 - count2 << endl;
- cin >> x >> y;
- --x; --y;
- p = (p + 1) % 2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement