# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38427 | Talant | Bomb (IZhO17_bomb) | C++14 | 1000 ms | 131072 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 fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const int N = (int)1e6 + 10;
int n,m;
char a[2502][2502];
int c[2502][2502];
int mx,mn = inf,mn1 = inf;
vector <pair<int,int> > v;
bool check (int h,int w) {
vector <pair<int,int> > t;
for (int l = 0; l < v.size(); l ++) {
int f = 0;
for (int i = max(v[l].fr,h); i <= min(n,v[l].fr + h - 1); i ++) {
for (int j = max(w,v[l].sc); j <= min(m,v[l].sc + w - 1); j ++) {
if (i - h < 0)
continue;
if (j - w < 0)
continue;
if (c[i][j] - c[i - h][j] - c[i][j - w] + c[i - h][j - w] == (h * w)) {
t.pb(mk(i,j));
f = 1;
break;
}
}
if (f == 1)
break;
}
if (!f)
return false;
}
return true;
}
int main () {
cin >> n >> m;
for (int i = 1; i <= n; i ++)
scanf ("%s", a[i] + 1);
for (int i = 1; i <= n; i ++) {
int cnt = 0;
for (int j = 1; j <= m; j ++) {
c[i][j] = int(a[i][j] - '0');
if (c[i][j] == 1)
v.pb(mk(i,j));
if (c[i][j] == 1)
cnt ++;
else {
if (cnt > 0)
mn = min(mn,cnt);
cnt = 0;
}
}
if (cnt > 0)
mn = min(mn,cnt);
}
for (int i = 1; i <= m; i ++) {
int cnt = 0;
for (int j = 1; j <= n; j ++) {
if (c[j][i] == 1)
cnt ++;
else {
if (cnt > 0)
mn1 = min(mn1,cnt);
cnt = 0;
}
}
if (cnt > 0)
mn1 = min(mn1,cnt);
}
if (mn == inf)
mn = 0;
if (mn1 == inf)
mn1 = 0;
if (mn * mn1 == 0) {
cout << 0;
return 0;
}
if (check(mn1,mn)) {
cout << mn1 * mn;
return 0;
}
for (int i = 1; i <= n; i ++)
for (int j = 2; j <= m; j ++)
c[i][j] += c[i][j - 1];
for (int i = 2; i <= n; i ++)
for (int j = 1; j <= m; j ++)
c[i][j] += c[i - 1][j];
for (int i = mn1; i >= 1; i --) {
for (int j = mn; j >= max(1,mn - (mn1 - i)); j --) {
if (mx >= i * j)
continue;
if (check(i,j)) {
cout << i * j << endl;
return 0;
}
if (check (j,i)) {
cout << i * j << endl;
return 0;
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |