Submission #846203

#TimeUsernameProblemLanguageResultExecution timeMemory
846203themm1Soccer Stadium (IOI23_soccer)C++17
0 / 100
1183 ms2097152 KiB
#include <bits/stdc++.h> #include "soccer.h" using namespace std; // ordered set whith s.order_of_key(x) method, which returns rank of element x in set s /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; */ // pair printing template <class T, class U> ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "(" << par.first << "; " << par.second << ")"; return out;} // set printing template <class T> ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; } // map printing template <class T, class U> ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; } // unordered_set printing template <class T> ostream& operator<<(ostream& out, const unordered_set<T> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;} // unordered_map printing template <class T, class U> ostream& operator<<(ostream& out, const unordered_map<T, U> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;} // vector printing template<class T> ostream& operator<<(ostream& out, const vector<T> &cont){ out << "["; for (const auto &x:cont) out << x << ", "; out << "]"; return out;} #define print(x) cout << (x) << endl; #define dmp(x) cerr << #x << " = " << x << endl #define dmpn(x) cerr << #x << " = " << x << "; " #define dmpl(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << x << endl using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define pb push_back #define ff first #define ss second #define all(x) begin(x), end(x) #define sz(x) (int)x.size() #define contains(s,x) ((s).find(x) != (s).end()) const int MOD = 998244353; vector<vector<int>> g; vector<vector<vector<vector<int>>>> memo; int N; pii prev_next(int j, vector<int> &tree_row, int N) { auto it_prev = lower_bound(all(tree_row), j); auto it_next = lower_bound(all(tree_row), j); int prev = (it_prev == begin(tree_row)) ? -1 : *(--it_prev); int next = (it_next == end(tree_row)) ? N : *(it_next); return { prev, next }; } vector<int> get_borders(vector<int> &row, int l, int r) { vector<int> borders = { l - 1 }; for (int j = l; j <= r; j++) if (row[j]) borders.pb(j); borders.pb(r + 1); return borders; } int recur(int row, int l, int r, int change) { bool d = (change == 1) ? false : true; if (row + change < 0 || row + change >= N) return r - l + 1; // dmpn(row); dmpn(d); dmpn(l); dmp(r); if (l == r && g[row][l] == 1) return 0; if (memo[d][row][l][r] != -1) return memo[d][row][l][r]; int ans = 0; vector<int> ones = get_borders(g[row + change], l, r); for (int i = 1; i < sz(ones); i++) { if (ones[i - 1] + 1 != ones[i]) ans = max(recur(row + change, ones[i - 1] + 1, ones[i] - 1, change), ans); } ans += r - l + 1; memo[d][row][l][r] = ans; return ans; } int biggest_stadium(int n, vector<vector<int>> F) { if (N >= 300) return -1; N = n; g = F; vector<pii> trees; vector<vector<int>> tree_rows(N); memo.assign(2, vector<vector<vector<int>>>(N, vector<vector<int>>(N, vector<int>(N, -1)))); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (F[i][j]) { trees.pb({ i, j }); tree_rows[i].pb(j); } int ans = N * N; /* if (sz(trees) <= 1) { if (sz(trees) == 0) return ans; int r = trees[0].ff, c = trees[0].ff; ans = max({ ans - (r + 1) * (c + 1), ans - (N - r) * (N - c), ans - (r + 1) * (N - c), ans - (c + 1) * (N - r), }); return ans; } */ // vector<int> last_tree(N, -1), next_tree(N); // for (int i = 0; i < N; i++) next_tree[i] = (!tree_rows[i].empty()) ? tree_rows[i][0] : N; ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (F[i][j]) continue; pii p = prev_next(j, tree_rows[i], N); // dmp(p); vector<int> borders = get_borders(g[min(i + 1, N - 1)], 0, N - 1); for (int bl = 1; bl < sz(borders); bl++) { // dmpn(borders[bl - 1]); dmp(borders[bl]); if (borders[bl - 1] + 1 == borders[bl]) continue; int up = 0, down = 0; if (i < N - 1) up = recur(i + 1, borders[bl - 1] + 1, borders[bl] - 1, 1); down = recur(i, p.ff + 1, p.ss - 1, -1); // dmpn(down); dmp(up); ans = max(ans, up + down); } } } return ans; } /* int32_t main() { int N; cin >> N; vector<vector<int>> F(N, vector<int>(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> F[i][j]; int ans = biggest_stadium(N, F); cout << ans << endl; } */
#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...