Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <iostream>
- #include <string>
- using namespace std;
- using ll = long long;
- void change(int col, int raw, vector <vector<int>> &desk, vector <int> &boys, int stepper) {
- //cout << "raw = " << raw << " col = " << col << '\n';
- raw = desk.size() - raw - 1;
- //cout << "raw = " << raw << " col = " << col << '\n';
- int yes = stepper; //чей ход
- int no = (stepper + 1) % 2;//кто не ходит
- if (desk[raw][col] == no) boys[no]--;
- desk[raw][col] = yes;
- boys[yes]++;
- //вверх
- bool up = false;
- int upper = -9;
- for (int i = raw - 1; i >= 0; --i) {
- if (desk[i][col] == yes) {
- up = true;
- upper = i;
- break;
- }
- }
- if (up) {
- for (int i = raw - 1; i > upper; --i) {
- if (desk[i][col] == no) boys[no]--;
- desk[i][col] = yes;
- boys[yes]++;
- }
- }
- //вниз
- bool down = false;
- int downer = -9;
- for (int i = raw + 1; i < (int)desk.size(); ++i) {
- if (desk[i][col] == yes) {
- down = true;
- downer = i;
- break;
- }
- }
- if (down) {
- for (int i = raw + 1; i < downer; ++i) {
- if (desk[i][col] == no) boys[no]--;
- desk[i][col] = yes;
- boys[yes]++;
- }
- }
- //влево
- bool left = false;
- int lefter = -9;
- for (int j = col - 1; j >= 0; --j) {
- if (desk[raw][j] == yes) {
- left = true;
- lefter = j;
- break;
- }
- }
- if (left) {
- for (int j = col - 1; j > lefter; --j) {
- if (desk[raw][j] == no) boys[no]--;
- desk[raw][j] = yes;
- boys[yes]++;
- }
- }
- //вправо
- bool right = false;
- int righter = -9;
- for (int j = col + 1; j < (int)desk[0].size(); ++j) {
- if (desk[raw][j] == yes) {
- right = true;
- righter = j;
- break;
- }
- }
- if (right) {
- for (int j = col + 1; j < righter; ++j) {
- if (desk[raw][j] == no) boys[no]--;
- desk[raw][j] = yes;
- boys[yes]++;
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int N, M;//N--размер по горизонтали, M-по вертикали
- cin >> N >> M;
- vector <vector<int>> desk(M, vector <int> (N, -9));
- vector <int> boys(2, 0);
- int stepper = -1;
- while (true) {
- int x, y;
- cin >> x >> y;
- stepper = (stepper + 1) % 2;
- if (x == -1 && y == -1) {
- //exit(0);
- break;
- }
- x--;
- y--;
- change(x, y, desk, boys, stepper);
- int dif = boys[0] - boys[1];
- cout << dif << endl;
- /*cout << "dif = " << dif << '\n';
- cout<<"desk\n";
- for (auto x : desk) {
- for (auto y : x) {
- cout << y << ' ';
- }cout << '\n';
- }cout << '\n';*/
- }
- }
- //в конце разобраться с flush
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement