Advertisement
erfanul007

UVa 10285

Jun 8th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. #define read() freopen("input.txt", "r", stdin)
  7. #define write() freopen("output.txt", "w", stdout)
  8.  
  9. void fastIO()
  10. {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. }
  14.  
  15. int mx,n,m,a[110][110];
  16.  
  17. void solve(int i,int j,int depth,int last)
  18. {
  19. if(i==0 || j==0 || i>n || j>m || a[i][j]>=last){
  20. mx = max(mx,depth);
  21. return;
  22. }
  23. solve(i+1,j,depth+1,a[i][j]);
  24. solve(i,j+1,depth+1,a[i][j]);
  25. solve(i-1,j,depth+1,a[i][j]);
  26. solve(i,j-1,depth+1,a[i][j]);
  27. }
  28.  
  29. int main()
  30. {
  31. //read();
  32. //write();
  33. fastIO();
  34. int t;
  35. cin>>t;
  36. while(t--){
  37. string s;
  38. cin>>s>>n>>m;
  39. cout<<s<<": ";
  40. for(int i=1;i<=n;i++){
  41. for(int j=1;j<=m;j++){
  42. cin>>a[i][j];
  43. }
  44. }
  45. mx = 0;
  46. for(int i=1;i<=n;i++){
  47. for(int j=1;j<=m;j++){
  48. solve(i+1,j,1,a[i][j]);
  49. solve(i,j+1,1,a[i][j]);
  50. solve(i-1,j,1,a[i][j]);
  51. solve(i,j-1,1,a[i][j]);
  52. }
  53. }
  54. cout<<mx<<'\n';
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement