aayyk

Untitled

May 9th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <functional>
  19. #include <unordered_set>
  20. #include <cstring>
  21. #include <cassert>
  22. #include <bitset>
  23. #ifdef LOCAL
  24. #include "debug.h"
  25. #else
  26. #define debug(x...)
  27. #endif
  28. //#define int ll
  29. //#pragma GCC optimize("Ofast")
  30.  
  31. using namespace std;
  32. typedef long long ll;
  33. typedef long double ld;
  34. typedef pair <int, int> pii;
  35. typedef pair <ll, ll> pll;
  36. #define sz(x) int((x).size())
  37.  
  38. #ifndef LOCAL
  39.     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  40. #else
  41.     mt19937 rng(228);
  42. #endif
  43.  
  44. const int N = 1e3 + 7;
  45. const int inf = INT_MAX / 2;
  46. const ll INF = LLONG_MAX / 3;
  47. const int MOD = 998244353;
  48. const ld eps = 1e-6;
  49. const string cars[] = {"πŸš—", "πŸš•", "πŸš™"};
  50.  
  51. struct Hasher {
  52.     size_t operator()(const pii& x) const {
  53.         return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  54.     }
  55. };
  56.  
  57. unordered_map < pii, bool, Hasher > used;
  58. const vector < pii > mv = { { 0, -1 }, { 0, 1 }, { 1, 0 }, { -1, 0 } };  
  59.  
  60. void bfs(int xs, int ys, int t) {
  61.     used[{ xs, ys }] = true;
  62.     queue < tuple < int, int, int > > q;
  63.     q.push({ xs, ys, t });
  64.  
  65.     while (!q.empty()) {
  66.         auto [x, y, t] = q.front();
  67.         q.pop();
  68.  
  69.         if (t > 0) {
  70.             for (auto [mx, my] : mv) {
  71.                 if (!used[{ x + mx, y + my }]) {
  72.                     used[{ x + mx, y + my }] = true;
  73.                     q.push({ x + mx, y + my, t - 1 });
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80. signed main() {
  81. #ifdef LOCAL
  82.     freopen("input.txt", "r", stdin);
  83.     freopen("output.txt", "w", stdout);
  84. #endif
  85.     cout << fixed << setprecision(9);
  86.     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  87.  
  88.     int k, c, t;
  89.     cin >> k >> c >> t;
  90.  
  91.     if (k == 1 && c == 0) {
  92.         cout << 1LL * 2 * t * (t + 1) + 1 << endl;
  93.     }
  94.     else {
  95.         vector < pii > a(k);
  96.         for (int i = 0; i < k; i++) {
  97.             cin >> a[i].first >> a[i].second;
  98.         }
  99.         for (int i = 0; i < c; i++) {
  100.             int x, y;
  101.             cin >> x >> y;
  102.  
  103.             used[{ x, y }] = true;
  104.         }
  105.  
  106.         for (auto[x, y] : a) {
  107.             bfs(x, y, t);
  108.         }
  109.  
  110.         int ans = 0;
  111.         for (auto[x, y] : used) {
  112.             ans += y;
  113.         }
  114.         cout << ans - c << endl;
  115.     }
  116.  
  117.     return 0;
  118. }
Add Comment
Please, Sign In to add comment