Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <deque>
- #include <algorithm>
- #include <iomanip>
- #include <set>
- #include <map>
- #include <cmath>
- #include <queue>
- #include <string>
- #include <stack>
- using namespace std;
- #define print(i) cout << i << '\n'
- #define pb push_back
- #define INF 100000000
- typedef long long llong;
- long double EPS = 1e-6;
- const int MAXN = (int)1e3;
- bool correct(int x, int y, int n) {
- if (x >= 0 &&
- x < n &&
- y >= 0 &&
- y < n) {
- return true;
- }
- return false;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int n;
- cin >> n;
- int A, B;
- cin >> A >> B;
- if (A + B == 0) {
- print(n * n);
- return 0;
- }
- n = min(n, 1000);
- set<pair<int, int>> was;
- int ans = 0;
- vector<pair<int, int>> Move{ { -B, -A }, { -B, A }, { -A, B }, { A, B }, { B, A }, { B, -A }, { -A, B }, { -A, -B } };
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- pair<int, int> start = { i, j };
- if (was.count(start) == 0) {
- queue<pair<int, int>> bfs;
- bfs.push(start);
- was.insert(start);
- while (!bfs.empty()) {
- auto cur = bfs.front();
- bfs.pop();
- for (auto dir : Move) {
- int x = cur.first + dir.first;
- int y = cur.second + dir.second;
- if (was.count({ x, y }) == 0 && correct(x, y, n)) {
- bfs.push({ x, y });
- was.insert({ x, y });
- }
- }
- }
- ans++;
- }
- }
- }
- print(ans);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement