Advertisement
paranid5

Vsesib2

Oct 18th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n = 0, m = 0;
  8.     scanf("%d%d", &n, &m);
  9.  
  10.     vector<vector<char>> tab(n, vector<char>(m, ' '));
  11.  
  12.     int x, y, guy = 1;
  13.     int f = 0, s = 0;
  14.  
  15.     while (true)
  16.     {
  17.         cin >> x >> y;
  18.         x--, y--;
  19.  
  20.         if (x < 0)
  21.             break;
  22.  
  23.         auto place = [&tab, &x, &y, &m, &n] (char ne, char old, int& guy1, int& guy2)
  24.         {
  25.           int up = x - 1;
  26.  
  27.           for (; up >= 0; up--)
  28.               if (tab[up][y] == ne)
  29.                   break;
  30.  
  31.           if (up != -1)
  32.           {
  33.               for (int i = x - 1; i > up; i--)
  34.               {
  35.                   if (tab[i][y] == old)
  36.                       guy2--;
  37.  
  38.                   tab[i][y] = ne;
  39.                   guy1++;
  40.               }
  41.           }
  42.  
  43.           int down = x + 1;
  44.  
  45.           for (; down < n; down++)
  46.               if (tab[down][y] == ne)
  47.                   break;
  48.  
  49.           if (down != n)
  50.           {
  51.               for (int i = x + 1; i < down; i++)
  52.               {
  53.                   if (tab[i][y] == old)
  54.                       guy2--;
  55.  
  56.                   tab[i][y] = ne;
  57.                   guy1++;
  58.               }
  59.           }
  60.  
  61.           int right = y + 1;
  62.  
  63.           for (; right < m; right++)
  64.               if (tab[x][right] == ne)
  65.                   break;
  66.  
  67.           if (right != m)
  68.           {
  69.               for (int i = y + 1; i < right; i++)
  70.               {
  71.                   if (tab[x][i] == old)
  72.                       guy2--;
  73.  
  74.                   tab[x][i] = ne;
  75.                   guy1++;
  76.               }
  77.           }
  78.  
  79.           int left = y - 1;
  80.  
  81.           for (; left >= 0; left--)
  82.               if (tab[x][left] == ne)
  83.                   break;
  84.  
  85.           if (left != -1)
  86.           {
  87.               for (int i = y - 1; i > left; i--)
  88.               {
  89.                   if (tab[x][i] == old)
  90.                       guy2--;
  91.  
  92.                   tab[x][i] = ne;
  93.                   guy1++;
  94.               }
  95.           }
  96.         };
  97.  
  98.         if (guy & 1)
  99.         {
  100.             if (tab[x][y] == 'B')
  101.                 s--;
  102.  
  103.             if (tab[x][y] != 'A')
  104.             {
  105.                 tab[x][y] = 'A';
  106.                 f++;
  107.             }
  108.  
  109.             place('A', 'B', f, s);
  110.         }
  111.  
  112.         else
  113.         {
  114.             if (tab[x][y] == 'A')
  115.                 f--;
  116.  
  117.             if (tab[x][y] != 'B')
  118.             {
  119.                 tab[x][y] = 'B';
  120.                 s++;
  121.             }
  122.  
  123.             place('B', 'A', s, f);
  124.         }
  125.  
  126.         cout << f - s << endl;
  127.         guy++;
  128.     }
  129.  
  130.     return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement