# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93314 | toloraia | Bomb (IZhO17_bomb) | C++14 | 1094 ms | 132096 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>
#define ll long long
#define F first
#define S second
using namespace std;
const int N = 5100;
int n, m;
char ch[N][N];
int a[N][N], b[N][N];
int c[N][N], d[N][N];
int A[N][N], B[N][N];
deque < pair < int, int > > Q;
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin>>ch[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (ch[i][j] == '1')
a[i][j] = a[i][j - 1] + 1;
for (int i = n; i >= 1; i--)
for (int j = m; j >= 1; j--)
if (ch[i][j] == '1')
b[i][j] = b[i][j + 1] + 1;
int ans = 1;
for (int I = 1; I <= n; I++){
for (int j = 1; j <= m; j++){
while ((int)Q.size() > 0)
Q.pop_back();
for (int i = 1; i <= n; i++){
while ((int)Q.size() > 0 && Q.back().F >= a[i][j])
Q.pop_back();
Q.push_back ({a[i][j], i});
while (Q.front().S <= i - I)
Q.pop_front();
c[max (1, i - I + 1)][j] = Q.front().F;
}
while ((int)Q.size() > 0)
Q.pop_back();
for (int i = 1; i <= n; i++){
while ((int)Q.size() > 0 && Q.back().F >= b[i][j])
Q.pop_back();
Q.push_back ({b[i][j], i});
while (Q.front().S <= i - I)
Q.pop_front();
d[max (1, i - I + 1)][j] = Q.front().F;
}
while ((int)Q.size() > 0)
Q.pop_back();
for (int i = 1; i <= n; i++){
while ((int)Q.size() > 0 && Q.back().F <= c[i][j])
Q.pop_back();
Q.push_back ({c[i][j], i});
while (Q.front().S <= i - I)
Q.pop_front();
A[i][j] = Q.front().F;
}
while ((int)Q.size() > 0)
Q.pop_back();
for (int i = 1; i <= n; i++){
while ((int)Q.size() > 0 && Q.back().F <= d[i][j])
Q.pop_back();
Q.push_back ({d[i][j], i});
while (Q.front().S <= i - I)
Q.pop_front();
B[i][j] = Q.front().F;
}
}
int J = m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (ch[i][j] == '1')
J = min (J, A[i][j] + B[i][j] - 1);
ans = max (ans, I * J);
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |