Advertisement
a53

LungimeRandMax1

a53
Oct 28th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. vector<vector<int>> w;
  5. vector<string> v;
  6. int maxi=0;
  7.  
  8. void fill(int k,int l,int p)
  9. {
  10. w[k][l]=p;
  11. maxi=max(maxi,p);
  12. if(k+1<(int)v.size())
  13. {
  14. if(l-1<(int)v[k+1].size()&&v[k+1][l-1]==' '&&w[k+1][l-1]==0)
  15. fill(k+1,l-1,++p),--p;
  16. if(l<(int)v[k+1].size()&&v[k+1][l]==' '&&w[k+1][l]==0)
  17. fill(k+1,l,++p),--p;
  18. if(l+1<(int)v[k+1].size()&&v[k+1][l+1]==' '&&w[k+1][l+1]==0)
  19. fill(k+1,l+1,++p),--p;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. string s;
  26. int l,n;
  27. cin>>l>>n;
  28. cin.get();
  29. for(int i=1;i<=n;++i)
  30. {
  31. getline(cin,s);
  32. w.push_back(vector<int>(s.size(),0));
  33. v.push_back(s);
  34. }
  35. for(int i=0;i<(int)v.size();++i)
  36. for(int j=0;j<(int)v[i].size();++j)
  37. if(v[i][j]==' ' && w[i][j]==0)
  38. fill(i,j,1);
  39. cout<<maxi;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement