Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make CSP great again
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- using namespace std;
- const int N = 5e2;
- bool Visited[N + 1][N + 1];
- int dx[] = {1, 1, -1, -1, 2, 2, -2, -2};
- int dy[] = {2, -2, 2, -2, 1, -1, 1, -1};
- int n;
- int res = 0;
- void DFS(int i, int j)
- {
- Visited[i][j] = true;
- ++res;
- for (int k = 0; k < 8; ++ k)
- {
- int x = dx[k] + i, y = dy[k] + j;
- if (x > 0 && x <= n && y > 0 && y <= n && Visited[x][y] == false)
- {
- DFS(x, y);
- }
- }
- }
- void read()
- {
- int x, y;
- cin >> n >> x >> y;
- DFS(x, y);
- }
- void solve()
- {
- cout << res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- if (fopen(TASK".INP", "r"))
- {
- freopen(TASK".INP", "r", stdin);
- //freopen(TASK".OUT", "w", stdout);
- }
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement