Advertisement
Brick99

DMOPC 13 Crossing field

May 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. int n,h;
  9. pair <bool,int> m[1501][1501];
  10.  
  11. void da_ne(int x, int y, int korak)
  12. {
  13.     if (x < 0 || x >= n || y < 0 || y >= n) return;
  14.     if (abs(m[x][y].second-korak) > h) return;
  15.     if (m[x][y].first == true) return;
  16.  
  17.     m[x][y].first=true;
  18.     if (x==n-1 && y==n-1) { n=-10;return; }
  19.  
  20.     da_ne(x+1,y,m[x][y].second);
  21.     da_ne(x-1,y,m[x][y].second);
  22.     da_ne(x,y+1,m[x][y].second);
  23.     da_ne(x,y-1,m[x][y].second);
  24. }
  25.  
  26. int main()
  27. {
  28.     cin>>n>>h;
  29.  
  30.     for (int i=0;i<n;i++)
  31.         for (int j=0;j<n;j++)
  32.         {
  33.             cin>>m[i][j].second;
  34.             m[i][j].first=false;
  35.         }
  36.  
  37.     da_ne(0,0,m[0][0].second);
  38.  
  39.     if (n==-10) cout<<"yes"<<endl;
  40.     else cout <<"no"<<endl;
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement