Submission #526613

#TimeUsernameProblemLanguageResultExecution timeMemory
526613dostigatorBomb (IZhO17_bomb)C++17
33 / 100
1108 ms110536 KiB
#include <bits/stdc++.h> #define pb push_back #define sz(v) (int)v.size() #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define x first #define y second #define int long long #define nl "\n" using namespace std; typedef long long ll; typedef pair<long long, long long> pll; typedef pair <ll, ll> pii; const int N = (int)1e6 + 7; const int M = (int)5e6 + 7; const ll MOD = (ll)1e9 + 7; const int inf = (int)1e9 + 7; const ll INF = (ll)3e18 + 7; pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}}; int n, m; char c[2501][2501]; int used[2501][2501], w[2501][2501]; int get(int x1, int y1, int x2, int y2) { return w[x2][y2] - w[x2][y1-1] - w[x1-1][y2] + w[x1-1][y1-1]; } void upd(int x1, int y1, int x2, int y2) { used[x1][y1]++; used[x1][y2+1]--; used[x2+1][y1]--; used[x2+1][y2+1]++; } void solve() { cin >> n >> m; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { cin >> c[i][j]; w[i][j] = w[i-1][j] + w[i][j-1] - w[i-1][j-1] + (c[i][j] == '1'); } } int ans = inf; if(n == 1) { int cur = 0; for(int i = 1; i <= m; ++i) { if(c[1][i] == '1') cur++; else { if(cur > 0) ans = min(ans, cur); cur = 0; } } if(c[1][m] == '1') ans = min(ans, cur); cout << ans << nl; return; } if(m == 1) { int cur = 0; for(int i = 1; i <= n; ++i) { if(c[i][1] == '1') cur++; else { if(cur > 0) ans = min(ans, cur); cur = 0; } } if(c[n][1] == '1') ans = min(ans, cur); cout << ans << nl; return; } ans = 0; int l = 1, r = n; while(l <= r) { int e = (l + r) >> 1; int L = 1, R = m; bool cur = 0; while(L <= R) { int f = (L + R) >> 1; for(int i = 1; i <= n; ++i) fill(used[i] + 1, used[i] + 1 + m, 0); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { if(i + e - 1 > n || j + f - 1 > m) break; int x = get(i, j, i + e - 1, j + f - 1); if(x == e * f) { upd(i, j, i + e - 1, j + f - 1); } } } for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { used[i][j] += used[i-1][j] + used[i][j-1] - used[i-1][j-1]; } } bool ok = 1; for(int i = 1; i <= n && ok; ++i) { for(int j = 1; j <= m && ok; ++j) { if(c[i][j] == '1') ok &= (used[i][j] > 0); } } if(ok) { cur = 1; ans = max(ans, e * f); L = f + 1; } else R = f - 1; } if(cur) l = e + 1; else r = e - 1; } if(n <= 100 && m <= 100) { for(int e = 1; e <= n; ++e) { for(int f = 1; f <= n; ++f) { bool ok = 1; for(int i = 1; i <= n; ++i) fill(used[i] + 1, used[i] + 1 + m, 0); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { if(i + e - 1 > n || j + f - 1 > m) break; int x = get(i, j, i + e - 1, j + f - 1); if(x == e * f) { upd(i, j, i + e - 1, j + f - 1); } } } for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { used[i][j] += used[i-1][j] + used[i][j-1] - used[i-1][j-1]; } } for(int i = 1; i <= n && ok; ++i) { for(int j = 1; j <= m && ok; ++j) { if(c[i][j] == '1') ok &= (used[i][j] > 0); } } if(ok) { ans = max(ans, e * f); //cout << e << ' ' << f << nl; } } } } cout << ans << nl; } signed main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int test = 1; //cin >> test; for(int i = 1; i <= test; ++i) { //cout << "Case " << i << ": "; solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...