Advertisement
Saleh127

UVA 11094

Jul 5th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl "\n"
  5. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  6. ll n,m,cnt;
  7. char a[200][200],c;
  8. bool v[200][200];
  9.  
  10. ll chk(ll j)
  11. {
  12. if(j<0ll) return m-1;
  13. else if(j>=m) return 0ll;
  14. else return j;
  15. }
  16.  
  17. void floodfill(ll i,ll j)
  18. {
  19. j=chk(j);
  20.  
  21. if(i<0 || i>=n || v[i][j] || a[i][j]!=c) return;
  22.  
  23. v[i][j]=1;
  24.  
  25. cnt++;
  26.  
  27. floodfill(i,j+1);
  28. floodfill(i,j-1);
  29. floodfill(i+1,j);
  30. floodfill(i-1,j);
  31. }
  32.  
  33. int main()
  34. {
  35. ios_base::sync_with_stdio(0);
  36. cin.tie(0);cout.tie(0);
  37.  
  38. while(cin>>n>>m)
  39. {
  40. ll i,j,k,l;
  41.  
  42. for(i=0;i<n;i++)
  43. {
  44. for(j=0;j<m;j++)
  45. {
  46. cin>>a[i][j];
  47. }
  48. }
  49.  
  50. cin>>i>>j;
  51.  
  52. c=a[i][j];
  53.  
  54. memset(v,0,sizeof v);
  55.  
  56. floodfill(i,j);
  57.  
  58. l=0;
  59.  
  60. for(i=0;i<n;i++)
  61. {
  62. for(j=0;j<m;j++)
  63. {
  64. cnt=0;
  65. floodfill(i,j);
  66. l=max(l,cnt);
  67. }
  68. }
  69.  
  70. cout<<l<<endl;
  71.  
  72. }
  73.  
  74. return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement