1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF(0x3f3f3f3f3f3f3f); const double ESP(1e-9); const ll mod(1e9+7); #define per(i, a, b) for(int i=a; i<b; i++) #define rep(i, a, b) for(int i=b-1; i>=a; i--) #define mem(a, b) memset(a, b, sizeof(a)) ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } const int MAXN(1e3 + 7); int n, m; string str; int high[MAXN]; int mxx, mxx2; int stkhg[MAXN], stkpos[MAXN]; int cnt; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; high[m+1] = 0; per(i, 1, n+1) { cin >> str; per(j, 1, m+1) { high[j] = str[j-1]=='0'?0:high[j]+1; } stkhg[0] = stkpos[0] = cnt = 0; per(j, 1, m+2) { if(high[j]>stkhg[cnt]) { stkhg[++cnt] = high[j]; stkpos[cnt] = j; } else if(high[j]<stkhg[cnt]) { while (high[j] < stkhg[cnt]) { int area = (j - stkpos[cnt]) * stkhg[cnt]; if (area >= mxx) { mxx2 = mxx; mxx = area; mxx2 = max(mxx2, max(area - stkhg[cnt], area - (j - stkpos[j]))); } else if (area > mxx2) { mxx2 = area; } cnt--; } if(stkhg[cnt]!=high[j]) { stkhg[++cnt] = high[j]; } } } } cout << mxx2 << endl; return 0; }
|