# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697342 | allllekssssa | Bomb (IZhO17_bomb) | C++14 | 1100 ms | 56380 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;
#define pii pair<int ,int>
#define pb push_back
const int maxN = 2600;
int n, m;
int a[maxN][maxN];
int d[maxN][maxN];
int c[maxN][maxN];
string s;
int cnt[maxN];
int getDSum(int x1, int y1, int x2, int y2) {
if (x2 > n || y2 > m) return 0;
return d[x2][y2] + d[x1 - 1][y1 - 1] - d[x1 - 1][y2] - d[x2][y1 - 1];
}
int heuristic1() {
vector<pii> gornji;
for (int i = 1; i<=n; i++) {
for (int j = 1; j<=m; j++) {
if (a[i - 1][j] == 0 && a[i][j - 1] == 0 && a[i][j] == 1) gornji.pb({i, j});
}
}
for (int i = 1; i <=n; i++) {
cnt[i] = m;
}
for (int i = 0; i < gornji.size(); i++) {
for (int len = 1; len <= n; len++) {
int width = m;
int x = gornji[i].first;
int y = gornji[i].second;
while ((width > 0 || cnt[len]) && getDSum(x, y, x + len - 1, y + width - 1) != len * width) width--;
cnt[len] = min(cnt[len], width);
}
}
int ans = 0;
for (int i = 1; i<=n; i++) {
ans = max(ans, i * cnt[i]);
}
return ans;
}
int main() {
cin >> n >> m;
for (int i = 1; i <=n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
a[i][j + 1] = s[j] - '0';
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j<=m; j++) {
d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
}
}
cout << heuristic1() << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |