Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("schior.in");
  4. ofstream fout("schior.out");
  5. int di[8]={0,0,1,-1,1,1,-1,-1};
  6. int dj[8]={1,-1,0,0,-1,1,-1,1};
  7.  
  8.  
  9. bool ok(int i,int j,int n,int m)
  10. {
  11. if (i<1||j<1||i>n||j>m) return false;
  12. return true;
  13. }
  14. int main()
  15. {
  16. int n,m;
  17. fin>>n>>m;
  18. int l,o;
  19. fin>>o>>l;
  20. int v[n+1][m+1];
  21. int w[n+1][m+1];
  22. memset(w,0,sizeof w);
  23. for (int i=1;i<=n;++i)
  24. for (int j=1;j<=m;++j)
  25. fin>>v[i][j];
  26. queue<pair<int, int> > q;
  27. w[o][l]=1;
  28. int altmin=v[o][l];
  29. q.push(make_pair(o,l));
  30. while (!q.empty())
  31. {
  32. int i,j;
  33. i=q.front().first;
  34. j=q.front().second;
  35. q.pop();
  36. for(int d=0;d<8;++d)
  37. {
  38. int ii,jj;
  39. ii=i+di[d];
  40. jj=j+dj[d];
  41. if (ok(ii,jj,n,m)&&v[ii][jj]<=v[i][j]&&w[ii][jj]==0)
  42. {
  43. if (v[ii][jj]<altmin) altmin=v[ii][jj];
  44.  
  45. w[ii][jj]=1;
  46. q.push(make_pair(ii,jj));
  47. }
  48. }
  49. }
  50. fout<<altmin;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement