Advertisement
a53

oaste2

a53
Jan 28th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("oaste2.in");
  4. ofstream g("oaste2.out");
  5. int a[102][102],n,m,s,r;
  6.  
  7. void citeste()
  8. {
  9. f>>n>>m;
  10. int i,j;
  11. for(i=1; i<=n; i++)
  12. for(j=1; j<=m; j++)
  13. f>>a[i][j];
  14. }
  15. void fill(int i, int j)
  16. {
  17. s=s+a[i][j];
  18. r++;
  19. a[i][j]=0;
  20. if(a[i-1][j])fill(i-1,j);
  21. if(a[i][j+1])fill(i,j+1);
  22. if(a[i+1][j])fill(i+1,j);
  23. if(a[i][j-1])fill(i,j-1);
  24. }
  25.  
  26. int main()
  27. {
  28. citeste();
  29. int i,j, S=0, R=10001;
  30. for(i=1;i<=n;i++)
  31. for(j=1;j<=m;j++)
  32. if(a[i][j])
  33. {
  34. r=0; s=0;
  35. fill(i,j);
  36. if(s>S)
  37. S=s,R=r;
  38. else
  39. if(s==S)
  40. R=min(R,r);
  41. }
  42. g<<S<<" "<<R<<endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement