0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 10:36:26 +00:00

P1565 牛宫

https://www.luogu.com.cn/record/84050544
This commit is contained in:
Baoshuo Ren 2022-08-16 19:26:48 +08:00
parent bf13736cc0
commit 51efd8f0d0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -8,7 +8,36 @@ const char endl = '\n';
const int N = 205;
int n, m;
long long g[N][N], ans;
long long g[N][N], s[N][N], c[N], ans;
bool check(int x) {
long long t = 0;
for (int i = x; i <= m; i++) {
t = std::min(t, c[i - x]);
if (c[i] > t) return true;
}
return false;
}
int calc() {
int l = 1, r = n, res = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
res = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
@ -20,19 +49,17 @@ int main() {
for (int j = 1; j <= m; j++) {
cin >> g[i][j];
g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
s[i][j] = s[i - 1][j] + g[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = i; k <= n; k++) {
for (int l = j; l <= m; l++) {
if (g[k][l] - g[k][j - 1] - g[i - 1][l] + g[i - 1][j - 1] >= 0) {
ans = std::max(ans, static_cast<long long>(k - i + 1) * (l - j + 1));
}
}
for (int j = i; j <= n; j++) {
for (int k = 1; k <= m; k++) {
c[k] = c[k - 1] + s[j][k] - s[i - 1][k];
}
ans = std::max(ans, static_cast<long long>(j - i + 1) * calc());
}
}