Advertisement
a53

SAO1

a53
Dec 13th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. int n,m;
  4. unsigned long long a[501][501],val,MAX,P;
  5.  
  6. unsigned long long umple(int i,int j)
  7. {
  8. /// Daca patratelul nu a mai fost parcurs
  9. if(a[i][j]!=0&&a[i][j]==val)
  10. {
  11. P+=a[i][j];
  12. a[i][j]=0; /// Il marcheaza
  13. if(i>1) umple(i-1,j); /// Incearca sa mearga mai sus
  14. if(j>1) umple(i,j-1); /// La stanga
  15. if(i<n) umple(i+1,j); /// Mai jos
  16. if(j<m) umple(i,j+1); /// La dreapta
  17. }
  18. return P;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. ifstream f("sao1.in");
  25. f>>n>>m;
  26. for(int i=1;i<=n;++i)
  27. for(int j=1;j<=m;++j)
  28. f>>a[i][j];
  29. f.close();
  30. for(int i=1;i<=n;++i)
  31. for(int j=1;j<=m;++j)
  32. if(a[i][j]!=0)
  33. {
  34. val=a[i][j];
  35. P=0;
  36. umple(i,j);
  37. if(P>MAX)
  38. MAX=P;
  39. }
  40. ofstream g("sao1.out");
  41. g<<MAX;
  42. g.close();
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement