Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream fin("acces.in");
  5. ofstream fout("acces.out");
  6.  
  7. int n, a[1005][1005];
  8. int b[1005][1005];
  9. int dx[] = {0, 0, 1, -1};
  10. int dy[] = {-1, 1, 0, 0};
  11. queue < pair < int, int > > Q;
  12. void Citire()
  13. {
  14. int i, j;
  15. fin >> n;
  16. for(i = 1; i <= n; i++)
  17. for(j = 1; j <= n; j++)
  18. fin >> a[i][j];
  19. fin.close();
  20. }
  21. void Bordare()
  22. {
  23. int i, j;
  24. for(i = 0; i <= n + 1; i++)
  25. {
  26. a[i][0] = a[i][n + 1] = 1000002;
  27. a[0][i] = a[n + 1][i] = 1000002;
  28. }
  29. }
  30. void Init()
  31. {
  32. int i, j;
  33. for(i = 1; i <= n; i++)
  34. for(j = 1; j <= n; j++)
  35. b[i][j] = 1000000;
  36. }
  37. void Lee()
  38. {
  39. int k, i, j, x, y;
  40. b[1][1] = a[1][1];
  41. Q.push({1, 1});
  42. while( !Q.empty())
  43. {
  44. i = Q.front().first;
  45. j = Q.front().second;
  46. Q.pop();
  47. for(k = 0; k < 4; k++)
  48. {
  49. x = i + dx[k];
  50. y = j + dy[k];
  51. if(b[x][y] > max(b[i][j], a[x][y]) && b[x][y] != 1000002)
  52. {
  53. b[x][y] = max(b[i][j], a[x][y]);
  54. Q.push({x, y});
  55. }
  56. }
  57. }
  58. fout << b[n][n] << "\n";
  59. fout.close();
  60. }
  61. int main()
  62. {
  63. Citire();
  64. Bordare();
  65. Init();
  66. Lee();
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement