# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388284 | patrikpavic2 | Bomb (IZhO17_bomb) | C++17 | 635 ms | 90316 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 <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define PB push_back
using namespace std;
const int N = 2505;
int n, m;
char s[N][N];
int A[N][N], B[N][N];
int par[N], L[N], R[N], un[N], nula[N];
int S[N];
int pr(int x){
if(x == par[x]) return x;
return par[x] = pr(par[x]);
}
void mrg(int x, int y){
if(x < 0 || y >= m || !un[x] || !un[y]) return;
// printf("mrg %d %d\n", x, y);
x = pr(x), y = pr(y);
if(x == y) return;
if(nula[x]) S[R[x] - L[x] + 1]--;
if(nula[y]) S[R[y] - L[y] + 1]--;
if(R[x] - L[x] > R[y] - L[y]){
par[y] = x; R[x] = R[y];
nula[x] |= nula[y];
if(nula[x])
S[R[x] - L[x] + 1]++;
}
else{
par[x] = y; L[y] = L[x];
nula[y] |= nula[x];
if(nula[y])
S[R[y] - L[y] + 1]++;
}
}
vector < int > kon[N];
int ans[N];
void odradi_redak(int rd){
for(int i = 0;i <= m;i++) S[i] = 0;
for(int i = 0;i <= n;i++) kon[i].clear();
for(int i = 0;i < m;i++){
un[i] = 0;
if(s[rd][i] == '0') continue;
par[i] = i; nula[i] = (B[rd][i] == 1);
L[i] = i, R[i] = i;
kon[A[rd][i]].PB(i);
if(nula[i]) S[0]++;
}
if(!S[0]) return;
int cur = 0;
for(int i = n;i >= 1;i--){
for(int x : kon[i]){
if(nula[x])
S[0]--, S[1]++;
// printf("x = %d nula = %d\n", x, nula[x]);
un[x] = 1;
mrg(x - 1, x);
mrg(x, x + 1);
}
while(!S[cur]) cur++;
//printf("rd = %d i = %d cur = %d\n", rd, i, cur);
ans[i] = min(ans[i], cur);
}
}
int main(){
//freopen("bomb.in", "r", stdin);
//freopen("bomb.out", "w", stdout);
scanf("%d%d", &n, &m);
int fin = n * m;
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
scanf(" %c", &s[i][j]);
for(int bla = 0;bla < 2;bla++){
memset(A, 0, sizeof(A));
memset(B, 0, sizeof(B));
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
A[i][j] = (1 + (i ? A[i - 1][j] : 0)) * (s[i][j] - '0');
for(int i = n - 1;i >= 0;i--)
for(int j = 0;j < m;j++)
B[i][j] = (1 + B[i + 1][j]) * (s[i][j] - '0');
for(int i = 1;i <= n;i++) ans[i] = m;
for(int i = 0;i < n;i++) odradi_redak(i);
int sol = 1;
for(int i = 1;i <= n;i++){
sol = max(sol, ans[i] * i);
//printf("ans[ %d ] = %d\n", i, ans[i]);
}
fin = min(fin, sol);
for(int i = 0;n - i - 1 > i;i++){
for(int j = 0;j < m;j++)
swap(s[i][j], s[n - i - 1][j]);
}
}
printf("%d\n", fin);
return 0;
}
/*
5 6
000000
111110
111110
111110
001000
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |