Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- using namespace std;
- int dx[]={1,-1,0,0};
- int dy[]={0, 0,1,-1};
- const int N=1010;
- vector<int> x,y,finalPoints;
- set< pair<int,int> > grid;
- int k;
- void blockInGrid() {
- int n=x.size();
- for(int i=0;i<n;i++) {
- auto t = make_pair(x[i],y[i]);
- grid.insert(t);
- }
- }
- void dfs(int x,int y,int t) {
- auto cur=make_pair(x,y);
- if(grid.count(cur)) {
- return ;
- }
- grid.insert(cur);
- if(t==k) {
- finalPoints.push_back(x);
- return;
- }
- for(int i=0;i<4;i++) {
- int nx=x+dx[i];
- int ny=y+dy[i];
- dfs(nx,ny,t+1);
- }
- }
- class TheGridDivTwo {
- public:
- int find(vector<int> _x, vector<int> _y, int _k) {
- x=_x;
- y=_y;
- k=_k;
- grid.clear();
- finalPoints.clear();
- blockInGrid();
- dfs(0,0,0);
- int res=0;
- for(int i : finalPoints) {
- res=max(res,i);
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement