# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93830 | dalgerok | Bomb (IZhO17_bomb) | C++14 | 465 ms | 61688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |