QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#294170 | #7120. Soccer | training4usaco | 0 | 0ms | 0kb | C++17 | 2.5kb | 2023-12-30 09:00:39 | 2024-04-28 08:28:47 |
Judging History
answer
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
const int MAXN = 2e3 + 5;
const int INF = 1e9 + 7;
int ans = 0;
int grid[MAXN][MAXN];
int up[MAXN][MAXN], down[MAXN][MAXN];
int dp[MAXN][MAXN];
int prv[MAXN][MAXN], nxt[MAXN][MAXN];
int len[MAXN][MAXN];
void magic(int row, int u, int l, int r) {
dp[row][u] = down[row][u] * (r - l + 1);
len[row][u] = r - l + 1;
if(prv[row][u] != -1) {
magic(row, prv[row][u], l, u - 1);
dp[row][u] = max(dp[row][u], dp[row][prv[row][u]] + (r - u + 1) * down[row][u]);
}
if(nxt[row][u] != -1) {
magic(row, nxt[row][u], u + 1, r);
dp[row][u] = max(dp[row][u], dp[row][nxt[row][u]] + (u - l + 1) * down[row][u]);
}
if(dp[row - 1][u] != -INF) dp[row][u] = max(dp[row][u], dp[row - 1][u] + (len[row][u] - len[row - 1][u]) * down[row][u]);
ans = max(ans, dp[row][u]);
}
int biggest_stadium(int n, vector<vector<int>> f) {
for(int i = 0; i <= n + 1; ++i) for(int j = 0; j <= n + 1; ++j) grid[i][j] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) grid[i][j] = f[i][j];
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(grid[i][j]) up[i][j] = 0;
else up[i][j] = up[i - 1][j] + 1;
}
}
for(int i = n; i >= 1; --i) {
for(int j = 1; j <= n; ++j) {
if(grid[i][j]) down[i][j] = 0;
else down[i][j] = down[i + 1][j] + 1;
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
dp[i][j] = -INF;
prv[i][j] = nxt[i][j] = -1;
}
}
for(int i = 1; i <= n; ++i) {
int l = 1, r = 0;
for(int j = 1; j <= n; ++j)
while(l <= n) {
r = l;
if(grid[i][l] == 1) {
while(r <= n && grid[i][r]) ++r;
l = r + 1;
continue;
}
while(r < n && grid[i][r + 1] == 0) ++r;
stack<int> st;
for(int j = l; j <= r; ++j) {
while(st.size() && down[i][st.top()] > down[i][j]) {
prv[i][j] = st.top(); st.pop();
}
if(st.size()) nxt[i][st.top()] = j;
st.push(j);
}
while(st.size() > 1) st.pop();
magic(i, st.top(), l, r);
}
}
return ans;
}
//int main() {}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L 1 0
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #10:
score: 0
Runtime Error
input:
R0R7sb2atQWJ6SAWOjw4ZG7Gwgo5zl9L 3 0 0 0 0 1 0 0 1 1
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%