# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173102 | VEGAnn | Bomb (IZhO17_bomb) | C++14 | 1108 ms | 102280 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>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
#define PB push_back
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2510;
const int oo = 2e9;
int n, m, ans, a[N][N], pref[N][N], vl[N][N], pl[N][N];
bool ok(int ht, int wd){
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
pl[i][j] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
if (i + ht - 1 > n || j + wd - 1 > m)
break;
int i1 = i + ht - 1, i2 = i - 1;
int j1 = j + wd - 1, j2 = j - 1;
int kol = pref[i1][j1] - pref[i2][j1] - pref[i1][j2] + pref[i2][j2];
if (kol > 0) continue;
pl[i][j]++; pl[i][j + wd]--;
pl[i + ht][j]--; pl[i + ht][j + wd]++;
}
for (int i = 1; i <= n; i++){
int cr = 0;
for (int j = 1; j <= m; j++){
cr += pl[i][j];
vl[i][j] = cr;
}
}
for (int j = 1; j <= m; j++){
int cr = 0;
for (int i = 1; i <= n; i++){
cr += vl[i][j];
if (a[i][j] == 1 && cr == 0)
return 0;
}
}
return 1;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
char c; cin >> c;
a[i][j] = (c == '1' ? 1 : 0);
pref[i][j] = (a[i][j] ^ 1) + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
int wd = m;
for (int ht = 1; ht <= n; ht++){
while (wd > 0 && !ok(ht, wd))
wd--;
if (wd == 0) break;
ans = max(ans, ht * wd);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |