Submission #1233436

#TimeUsernameProblemLanguageResultExecution timeMemory
1233436antonnSoccer Stadium (IOI23_soccer)C++20
0 / 100
8 ms15684 KiB
#include "soccer.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000 + 7; const int M = 30 + 7; int a[N][N], pref[N][N]; int dp[M][M][M][M]; /* 5 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 */ bool ok(int l, int x, int y) { return pref[l][y] - pref[l][x - 1] == 0; } int biggest_stadium(int n, vector<vector<int>> f) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { a[i][j] = f[i - 1][j - 1]; pref[i][j] = pref[i][j - 1] + a[i][j]; } } { vector<pair<int, int>> p(n + 1); bool all = 1; int total = 0; for (int i = 1; i <= n; ++i) { int cnt = 0; int l = 1e9, r = 0; for (int j = 1; j <= n; ++j) { if (a[i][j] == 0) { ++cnt; l = min(l, j); r = max(r, j); } } p[i] = {l, r}; if (cnt != 0 && r - l + 1 != cnt) { all = 0; } total += cnt; } int lines = 0; for (int i = 1; i <= n; ++i) if (p[i].first != 1e9) lines++; int f = -1, l = -1; for (int i = 1; i <= n; ++i) { if (p[i].first != 1e9) { if (f == -1) f = i; l = i; } } if (l - f + 1 != lines) all = false; for (int i = f; i <= l; ++i) { for (int j = i; j <= l; ++j) { if (p[i].first <= p[j].first && p[j].second <= p[i].second) continue; if (p[j].first <= p[i].first && p[i].second <= p[j].second) continue; all = 0; } } if (all) return total; if (n > 30) return -1; } for (int down = 0; down < N; ++down) { for (int up = down; up < N; ++up) { for (int x = 0; x < N; ++x) { for (int y = x; y < N; ++y) { dp[down][up][x][y] = -1e9; } } } } for (int i = 1; i <= n; ++i) { for (int l = 1; l <= n; ++l) { for (int r = l; r <= n; ++r) { if (ok(i, l, r)) dp[i][i][l][r] = r - l + 1; } } } for (int h = n; h >= 1; --h) { for (int l = 1; l + h - 1 <= n; ++l) { int r = l + h - 1; for (int h2 = 1; h2 <= n; ++h2) { for (int down = 1; down + h2 - 1 <= n; ++down) { int up = down + h2 - 1; for (int x = l; x <= r; ++x) { for (int y = x; y <= r; ++y) { if (ok(down - 1, x, y)) { dp[down - 1][up][x][y] = max(dp[down - 1][up][x][y], dp[down][up][l][r] + y - x + 1); } if (ok(up + 1, x, y)) { dp[down][up + 1][x][y] = max(dp[down][up + 1][x][y], dp[down][up][l][r] + y - x + 1); } } } } } } } int ans = 0; for (int down = 1; down <= n; ++down) { for (int up = down; up <= n; ++up) { for (int l = 1; l <= n; ++l) { for (int r = l; r <= n; ++r) { ans = max(ans, dp[down][up][l][r]); } } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...