Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <deque>
  4. #include <algorithm>
  5. #include <iomanip>
  6. #include <set>
  7. #include <map>
  8. #include <cmath>
  9. #include <queue>
  10. #include <string>
  11. #include <stack>
  12.  
  13. using namespace std;
  14.  
  15. #define print(i) cout << i << '\n'
  16. #define pb push_back
  17. #define INF 100000000
  18.  
  19. typedef long long llong;
  20.  
  21. long double EPS = 1e-6;
  22.  
  23. const int MAXN = (int)1e3;
  24.  
  25. bool correct(int x, int y, int n) {
  26. if (x >= 0 &&
  27. x < n &&
  28. y >= 0 &&
  29. y < n) {
  30. return true;
  31. }
  32. return false;
  33. }
  34.  
  35. int main()
  36. {
  37. ios_base::sync_with_stdio(false);
  38. cin.tie(NULL);
  39. cout.tie(NULL);
  40. int n;
  41. cin >> n;
  42. int A, B;
  43. cin >> A >> B;
  44. if (A + B == 0) {
  45. print(n * n);
  46. return 0;
  47. }
  48. n = min(n, 1000);
  49. set<pair<int, int>> was;
  50. int ans = 0;
  51. vector<pair<int, int>> Move{ { -B, -A }, { -B, A }, { -A, B }, { A, B }, { B, A }, { B, -A }, { -A, B }, { -A, -B } };
  52. for (int i = 0; i < n; i++) {
  53. for (int j = 0; j < n; j++) {
  54. pair<int, int> start = { i, j };
  55. if (was.count(start) == 0) {
  56. queue<pair<int, int>> bfs;
  57. bfs.push(start);
  58. was.insert(start);
  59. while (!bfs.empty()) {
  60. auto cur = bfs.front();
  61. bfs.pop();
  62. for (auto dir : Move) {
  63. int x = cur.first + dir.first;
  64. int y = cur.second + dir.second;
  65. if (was.count({ x, y }) == 0 && correct(x, y, n)) {
  66. bfs.push({ x, y });
  67. was.insert({ x, y });
  68. }
  69. }
  70. }
  71. ans++;
  72. }
  73. }
  74. }
  75. print(ans);
  76. return(0);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement