Submission #1007115

#TimeUsernameProblemLanguageResultExecution timeMemory
1007115NeroZeinSoccer Stadium (IOI23_soccer)C++17
8 / 100
4558 ms600 KiB
#include "soccer.h" #include <bits/stdc++.h> using namespace std; int n; pair<int, int> get(int x) { return {x / n, x % n}; } int dr[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int biggest_stadium(int N_, vector<vector<int>> F) { n = N_; vector<vector<int>> ps(n, vector<int> (n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { ps[i][j] = F[i][j]; if (i) ps[i][j] += ps[i - 1][j]; if (j) ps[i][j] += ps[i][j - 1]; if (i && j) ps[i][j] -= ps[i - 1][j - 1]; } } auto sum = [&](int x, int y, int i, int j) { if (x > i) swap(x, i); if (y > j) swap(y, j); int ret = ps[i][j]; if (y) { ret -= ps[i][y - 1]; } if (x) { ret -= ps[x - 1][j]; } if (x && y) { ret += ps[x - 1][y - 1]; } return ret; }; function<int(int, int, vector<vector<int>>&)> Dfs = [&](int x, int y, vector<vector<int>>& used) { if (x < 0 || x >= n || y < 0 || y >= n || !used[x][y]) return 0; used[x][y] = 0; int ret = 1; for (int j = 0; j < 4; ++j) { int nx = x + dr[j], ny = y + dy[j]; ret += Dfs(nx, ny, used); } return ret; }; int ans = 0; for (int i = 1; i < (1 << (n * n)); ++i) { vector<vector<int>> used(n, vector<int> (n)); bool bad = false; vector<pair<int, int>> vec; int sx = 0, sy = 0; for (int j = 0; j < n * n; ++j) { if (i >> j & 1) { auto [x, y] = get(j); sx = x, sy = y; vec.emplace_back(x, y); used[x][y] = 1; if (F[x][y]) { bad = true; } } } if (bad) { continue; } bool ok = Dfs(sx, sy, used) == __builtin_popcount(i); for (int k = 0; k < (int) vec.size(); ++k) { for (int l = 0; l < (int) vec.size(); ++l) { if (k == l) continue; auto [x, y] = vec[k]; auto [xx, yy] = vec[l]; bool cur = sum(x, y, x, yy) == 0 && sum(x, yy, xx, yy) == 0; cur |= sum(x, y, xx, y) == 0 && sum(xx, y, xx, yy) == 0; ok &= cur; } } if (ok) { ans = max(ans, __builtin_popcount(i)); } } 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...