Submission #878843

#TimeUsernameProblemLanguageResultExecution timeMemory
878843SanguineChameleonSoccer Stadium (IOI23_soccer)C++17
8 / 100
4559 ms4544 KiB
#include "soccer.h" #include <bits/stdc++.h> using namespace std; const int maxN = 2e3 + 20; int A[maxN][maxN]; int prv[maxN][maxN][2]; int top[maxN][maxN]; int bottom[maxN][maxN]; vector<pair<int, int>> group[maxN]; int dp[maxN][maxN]; int biggest_stadium(int N, vector<vector<int>> _A) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { A[i][j] = _A[i - 1][j - 1]; } } vector<pair<int, int>> cells; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (A[i][j] == 0) { cells.emplace_back(i, j); } } } int real_res = 0; for (int mask = 0; mask < (1 << (int)cells.size()); mask++) { vector<pair<int, int>> choice; for (int i = 0; i < (int)cells.size(); i++) { if ((mask >> i) & 1) { choice.push_back(cells[i]); } } bool ok = true; for (auto [i1, j1]: choice) { for (auto [i2, j2]: choice) { bool check1 = true; bool check2 = true; for (int k = min(j1, j2); k <= max(j1, j2); k++) { check1 &= (A[i1][k] == 0); check2 &= (A[i2][k] == 0); } for (int k = min(i1, i2); k <= max(i1, i2); k++) { check1 &= (A[k][j2] == 0); check2 &= (A[k][j1] == 0); } ok &= (check1 || check2); } } if (ok) { real_res = max(real_res, (int)choice.size()); } } return real_res; for (int i = 0; i <= N + 1; i++) { A[0][i] = 1; A[N + 1][i] = 1; A[i][0] = 1; A[i][N + 1] = 1; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 0; k < 2; k++) { if (A[i][j] == k) { prv[i][j][k] = j; } else { prv[i][j][k] = prv[i][j - 1][k]; } } } } for (int j = 0; j <= N; j++) { top[0][j] = 0; bottom[N + 1][j] = N + 1; } for (int i = 1; i <= N; i++) { for (int j = 0; j <= N; j++) { if (A[i - 1][j] == 1) { top[i][j] = i - 1; } else { top[i][j] = top[i - 1][j]; } } } for (int i = N; i >= 1; i--) { for (int j = 0; j <= N; j++) { if (A[i + 1][j] == 1) { bottom[i][j] = i + 1; } else { bottom[i][j] = bottom[i + 1][j]; } } } for (int i = N; i >= 1; i--) { for (int j = 1; j <= N; j++) { if (A[i][j] == 0) { if (A[i][j - 1] == 0) { top[i][j] = max(top[i][j], top[i][j - 1]); bottom[i][j] = min(bottom[i][j], bottom[i][j - 1]); } group[j - prv[i][j][1]].emplace_back(i, j); } } } int res = 0; for (int W = N; W >= 1; W--) { for (auto [i, j]: group[W]) { if (top[i][j] + 1 <= top[i][prv[i][j][1]]) { dp[prv[i][j][1]][j] = max(dp[prv[i][j][1]][j], dp[i][j]); continue; } int L = prv[i][j][1] + 1; int R = j; int T = top[i][j] + 1; int B = bottom[i][j] - 1; //cout << i << " " << j << " " << L << " " << R << " " << T << " " << B << " " << dp[i][j] << " " << dp[i][j] + (R - L + 1) * (B - T + 1) << '\n'; res = max(res, dp[i][j] + (R - L + 1) * (B - T + 1)); for (int iter = 0; iter < 2; iter++) { int row = (iter ? B + 1 : T - 1); if (row < 1 || row > N) { continue; } int nxtR = prv[row][R][0]; while (nxtR >= L) { int nxtL = max(L, prv[row][nxtR][1] + 1); int nxt_row = (nxtL == L ? i : row); //cout << nxt_row << " " << nxtR << " " << "real?" << '\n'; dp[nxt_row][nxtR] = max(dp[nxt_row][nxtR], dp[i][j] + ((R - L + 1) - (nxtR - nxtL + 1)) * (B - T + 1)); nxtR = prv[row][nxtL - 1][0]; } } } } return res; }
#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...