Submission #854585

#TimeUsernameProblemLanguageResultExecution timeMemory
854585The_SamuraiBomb (IZhO17_bomb)C++17
38 / 100
1102 ms55892 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const int inf = 1e9, N = 1e6 + 5; struct Fenwick_2d { vector<vector<int>> tree; int l1, l2; void init(int n, int m) { l1 = n; l2 = m; tree.assign(l1 + 1, vector<int>(l2 + 1, 0)); } void update(int x, int y, int v) { x++; y++; for (; x <= l1; x += x & (-x)) { for (int yy = y; yy <= l2; yy += yy & (-yy)) { tree[x][yy] += v; } } } int get(int x, int y) { x++; y++; int sum = 0; for (; x > 0; x -= x & (-x)) { for (int yy = y; yy > 0; yy -= yy & (-yy)) { sum += tree[x][yy]; } } return sum; } int get(int x1, int y1, int x2, int y2) { return get(x2, y2) - get(x2, y1 - 1) - get(x1 - 1, y2) + get(x1 - 1, y1 - 1); } }; int main() { cin.tie(0)->sync_with_stdio(false); #ifdef sunnatov freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen("game.in", "r", stdin); // freopen("game.out", "w", stdout); #endif int n, m; cin >> n >> m; vector<vector<char>> a(n + 1, vector<char>(m + 1)); Fenwick_2d fw; fw.init(n + 1, m + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == '1') fw.update(i, j, 1); } vector<vector<int>> checked(n + 1, vector<int>(m + 1)); int z = 0; auto check = [&](int h, int w) { z++; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == '0') continue; if (i + h - 1 <= n and j + w - 1 <= m and fw.get(i, j, i + h - 1, j + w - 1) == h * w) { for (int x = i; x < i + h; x++) { for (int y = j; y < j + w; y++) { checked[x][y] = z; } } } if (checked[i][j] < z) return false; } } return true; }; vector<int> best(n + 1, -1); auto get = [&](int h) { if (best[h] != -1) return best[h]; int lx = 1, rx = (h > 1 ? best[h - 1] : m); best[h] = 0; while (lx <= rx) { int mid = (lx + rx) >> 1; if (check(h, mid)) { best[h] = mid; lx = mid + 1; } else { rx = mid - 1; } } return best[h]; }; int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, get(i) * i); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...