Advertisement
Fahim_7861

maximum square (which is a square containing all ‘1’s.)

Feb 18th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. typedef int ll;
  7. typedef unsigned long long ull;
  8. typedef pair<ll,ll>pll;
  9. typedef pair<int,int>pii;
  10. //typedef pair<int,pair<int,int>>piii;
  11. //typedef pair<ll,pair<ll,ll>>plll;
  12. //typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> orderedSet;
  13. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  14. #define sf(a) scanf("%I64d",&a)
  15. #define pf(a) printf("%I64d\n",a)
  16. #define mem(a,b) memset(a,b,sizeof(a))
  17. #define vll(v) v.begin(),v.end()
  18. #define all(x) x.rbegin(),x.rend()
  19. #define min3(a, b, c) min(a, min(b, c))
  20. #define F first
  21. #define S second
  22. #define minheap int,vector<int>,greater<int>
  23. //#define mp make_pair
  24. #define pb push_back
  25. #define pp pop_back
  26. #define eb emplace_back
  27. #define in freopen("input.txt", "r", stdin)
  28. #define out freopen("output.txt", "w", stdout)
  29. #define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
  30. #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  31. #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
  32. const int Max = 1005;
  33. const int Mod = 1e9 + 7;
  34. const double PI =3.141592653589793238463;
  35. bool compare(const pair<int,int> &a, const pair<int,int> &b)
  36. {
  37. return (a.first > b.first);
  38. }
  39. ll lcm(ll a,ll b)
  40. {
  41. if(a==0 || b==0)return 0;
  42.  
  43. return a/__gcd(a,b)*b;
  44. }
  45. //___________________________________________________________________________________________________________________
  46. // CODE STARTS FROM HERE
  47. // MU_Codefighter2019
  48. //-------------------------------------------------------------------------------------------------------------------
  49.  
  50. ll ara[Max][Max],cum[Max][Max],n,m;
  51.  
  52. void input()
  53. {
  54. ll i,j;
  55.  
  56. for(i=1; i<=n; i++)
  57. {
  58. for(j=1; j<=m; j++)
  59. {
  60. scanf("%d",&ara[i][j]);
  61.  
  62. if(ara[i][j])
  63. {
  64. cum[i][j]=cum[i-1][j]+1;
  65. }
  66. else
  67. cum[i][j]=0;
  68. }
  69. }
  70. }
  71.  
  72. ll solution()
  73. {
  74. ll pos,i,j,len,sq,ans=0;
  75.  
  76. for(i=1; i<=n; i++)
  77. {
  78. for(j=1; j<=m; j++)
  79. {
  80. if(cum[i][j])
  81. {
  82. len=1;
  83.  
  84. pos=j;
  85.  
  86. sq=cum[i][j];
  87.  
  88. while(j<=m and sq>=len)
  89. {
  90. j++;
  91.  
  92. if(cum[i][j]<sq)
  93. {
  94. sq=cum[i][j];
  95.  
  96. pos=j;
  97. }
  98. len++;
  99. }
  100.  
  101. j=pos;
  102.  
  103. ans=max(ans,len-1);
  104.  
  105.  
  106.  
  107. }
  108. }
  109. }
  110.  
  111. return ans;
  112. }
  113.  
  114.  
  115. int main()
  116. {
  117. fastread();
  118.  
  119. ll cas=1,t,i,k;
  120.  
  121.  
  122. while(scanf("%d %d",&n,&m) && (n || m))
  123. {
  124. input();
  125.  
  126. printf("%d\n",solution());
  127. }
  128.  
  129.  
  130.  
  131.  
  132. }
  133.  
  134. // problem : https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2868
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement