Submission #93830

#TimeUsernameProblemLanguageResultExecution timeMemory
93830dalgerokBomb (IZhO17_bomb)C++14
100 / 100
465 ms61688 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2505, INF = 2e9; int n, m, dn[N][N], up[N][N]; char a[N][N]; int dp[N]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> a[i][j]; } } int mnw = INF, mnh = INF; for(int i = 1; i <= n; i++){ int cur = 0; for(int j = 1; j <= m; j++){ if(a[i][j] == '1'){ cur += 1; } else if(cur > 0){ mnw = min(mnw, cur); cur = 0; } } if(cur > 0){ mnw = min(mnw, cur); } } for(int j = 1; j <= m; j++){ int cur = 0; for(int i = 1; i <= n; i++){ if(a[i][j] == '1'){ cur += 1; } else if(cur > 0){ mnh = min(mnh, cur); cur = 0; } } if(cur > 0){ mnh = min(mnh, cur); } } for(int j = 1; j <= m; j++){ for(int i = 1; i <= n; i++){ if(a[i][j] == '1'){ up[i][j] = up[i - 1][j] + 1; } } for(int i = n; i >= 1; i--){ if(a[i][j] == '1'){ dn[i][j] = dn[i + 1][j] + 1; } } } for(int i = 1; i <= mnw; i++){ dp[i] = mnh; } for(int i = 1; i <= n; i++){ int l = INF, r = INF, cur = 0; for(int j = 1; j <= m; j++){ if(a[i][j] == '1'){ l = min(l, up[i][j]); r = min(r, dn[i][j]); cur += 1; dp[cur] = min(dp[cur], l + r - 1); } else{ l = r = INF; cur = 0; } } l = r = INF; cur = 0; for(int j = m; j >= 1; j--){ if(a[i][j] == '1'){ l = min(l, up[i][j]); r = min(r, dn[i][j]); cur += 1; dp[cur] = min(dp[cur], l + r - 1); } else{ l = r = INF; cur = 0; } } } int ans = dp[1]; for(int i = 2; i <= mnw; i++){ dp[i] = min(dp[i], dp[i - 1]); ans = max(ans, dp[i] * i); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...