Advertisement
Korotkodul

Антон_Задача 2. Реверс

Oct 15th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace __gnu_pbds;
  4. using namespace std;
  5. using ui = unsigned int;
  6. using ll = long long;
  7. using ull = unsigned long long;
  8. using ld = long double;
  9. using pii = pair<int, int>;
  10. using pll = pair<ll, ll>;
  11. using vi = vector<int>;
  12. using vll = vector<ll>;
  13. using vvi = vector<vi>;  
  14. using vpii = vector<pii>;
  15. template <typename key_type, typename value_type, typename comp = less<key_type>>
  16. using rbt_map = tree<key_type, value_type, comp, rb_tree_tag, tree_order_statistics_node_update>;
  17. template <typename key_type, typename comp = less<key_type>>
  18. using rbt_set = rbt_map<key_type, null_type, comp>;
  19. #define F(i, a, b) for(int i = (int)a; i <= (int)b; i++)
  20. #define f(i, a, b) for(int i = (int)a; i >= (int)b; i--)
  21. #define Fk(k, i, a, b) for(int i = (int)a; i <= (int)b; i += k)
  22. #define fk(k, i, a, b) for(int i = (int)a; i >= (int)b; i -= k)
  23. #define PB push_back
  24. #define MP make_pair
  25. #define MT make_tuple
  26. #define trans int tm = (tl + tr)>>1, l = v<<1, r = l|1
  27. template <typename value_type, typename relax_type = value_type, typename predictor = less<value_type>>
  28. void relax_pred(value_type& val, const relax_type& rel) { static predictor pred; if (pred(val, rel)) val = rel; }
  29. template <typename type>
  30. void relax_min(type& val, const type& rel) { relax_pred<type, type, greater<type>>(val, rel); }
  31. template <typename type>
  32. void relax_max(type& val, const type& rel) { relax_pred<type, type, less<type>>(val, rel); }
  33. ld const PI = acos(-1);
  34. ///#include "C:\programming\structures\IO_templates\int128_io.h"
  35. ///#include "C:\programming\structures\IO_templates\fast_io.h"
  36. ///#include "C:\programming\structures\big_integer.h"
  37. ///#include "C:\programming\structures\Math\Combinatorics.h"
  38. ///using namespace combinatorics;
  39.  
  40. int const N = 5002;
  41. int mp[N][N];
  42. int cnt[2];
  43. pii mv[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
  44.  
  45. void make_move(int pl, int x, int y) {
  46.     if (mp[x][y] != 2)
  47.         --cnt[mp[x][y]];
  48.     mp[x][y] = pl;
  49.     ++cnt[pl];
  50.    
  51.     for (auto [dx, dy] : mv) {
  52.         int ex = -1, ey = -1;
  53.         int cx = x + dx, cy = y + dy;
  54.         for (; mp[cx][cy] != 3; cx += dx, cy += dy) {
  55.             if (mp[cx][cy] == pl) {
  56.                 ex = cx, ey = cy;
  57.                 break;
  58.             }  
  59.         }
  60.         if (ex != -1) {
  61.             cx = x + dx, cy = y + dy;
  62.             for (; cx != ex || cy != ey; cx += dx, cy += dy) {
  63.                 if (mp[cx][cy] != 2)
  64.                     --cnt[mp[cx][cy]];
  65.                 mp[cx][cy] = pl;
  66.                 ++cnt[pl];
  67.             }
  68.         }
  69.     }
  70. }
  71. //#define LOCAL
  72. int main(){
  73.     ios_base::sync_with_stdio(false);
  74.     cin.tie(NULL);
  75.     #ifdef LOCAL
  76.     freopen("in", "r", stdin);
  77.     freopen("out", "w", stdout);
  78.     #endif
  79.     int n, m;
  80.     cin >> n >> m;
  81.    
  82.     F(i, 0, n + 1)
  83.         F(j, 0, m + 1)
  84.             mp[i][j] = (i == 0 || j == 0 || i == n + 1 || j == m + 1 ? 3 : 2);
  85.    
  86.     int x, y, turn = 0;
  87.     cin >> x >> y;
  88.     while (x != -1) {
  89.         make_move(turn, x, y);
  90.         cout << cnt[0] - cnt[1] << endl;
  91.         cin >> x >> y;
  92.         turn ^= 1;
  93.     }
  94.     return 0;
  95. }              
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement