Advertisement
Saleh127

spoj ABCPATH

Sep 27th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll v[60][60],r,c,ss;
  6. ll dx[]={0,-1,-1,-1, 0, 1,1,1};
  7. ll dy[]={1, 1, 0,-1,-1,-1,0,1};
  8.  
  9. string a[100];
  10.  
  11. ll dfs(ll i,ll j)
  12. {
  13. v[i][j]=ss;
  14. ll ans=1;
  15. for(ll k=0;k<8;k++)
  16. {
  17. ll x=i+dx[k];
  18. ll y=j+dy[k];
  19. if(x>=0 && x<r && y>=0 && y<c && v[x][y]!=ss)
  20. {
  21. if(a[i][j]+1==a[x][y])
  22. {
  23. ans=max(ans,1+dfs(x,y));
  24. }
  25. }
  26. }
  27. return ans;
  28. }
  29.  
  30. int main()
  31. {
  32. ios_base::sync_with_stdio(0);
  33. cin.tie(0);cout.tie(0);
  34.  
  35. ll cas=1;
  36. while(cin>>r>>c && r&&c)
  37. {
  38. cout<<"Case "<<cas++<<": ";
  39. for(ll i=0;i<r;i++)
  40. {
  41. cin>>a[i];
  42. }
  43. ll ans=0;
  44.  
  45. for(ll i=0;i<r;i++)
  46. {
  47. for(ll j=0;j<c;j++)
  48. {
  49. if(a[i][j]=='A')
  50. {
  51. ss++;
  52. ans=max(ans,dfs(i,j));
  53. }
  54. }
  55. }
  56. cout<<ans<<endl;
  57. }
  58.  
  59. return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement