Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int n,h;
- pair <bool,int> m[1501][1501];
- void da_ne(int x, int y, int korak)
- {
- if (x < 0 || x >= n || y < 0 || y >= n) return;
- if (abs(m[x][y].second-korak) > h) return;
- if (m[x][y].first == true) return;
- m[x][y].first=true;
- if (x==n-1 && y==n-1) { n=-10;return; }
- da_ne(x+1,y,m[x][y].second);
- da_ne(x-1,y,m[x][y].second);
- da_ne(x,y+1,m[x][y].second);
- da_ne(x,y-1,m[x][y].second);
- }
- int main()
- {
- cin>>n>>h;
- for (int i=0;i<n;i++)
- for (int j=0;j<n;j++)
- {
- cin>>m[i][j].second;
- m[i][j].first=false;
- }
- da_ne(0,0,m[0][0].second);
- if (n==-10) cout<<"yes"<<endl;
- else cout <<"no"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement