Submission #772319

#TimeUsernameProblemLanguageResultExecution timeMemory
772319marvinthangPrisoner Challenge (IOI22_prison)C++17
100 / 100
9 ms1072 KiB
/************************************* * author: marvinthang * * created: 04.07.2023 08:51:20 * *************************************/ #include "prison.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } // end of template vector <vector <int>> devise_strategy(int N) { vector <int> dp(21); vector <int> trace(21); dp[0] = 2; FOR(i, 1, 21) FORE(j, 1, i) if (maximize(dp[i], j * dp[i - j] + 2)) trace[i] = j; int X = 0; while (dp[X] < N) ++X; vector <vector <int>> res(X + 1, vector<int>(dp[X] + 1)); function<void(int, int, int, int, int, int, int)> solve = [&] (int x, int l, int r, int pl, int pr, int cur, int d) { int prv = !cur; res[x][0] = cur; FORE(i, pl, l) res[x][i] = -1 - cur; FORE(i, r, pr) res[x][i] = -1 - prv; ++l; --r; if (l > r) return; if (trace[d] == 3) { int m1 = l + (r - l + 1) / 3 - 1; int m2 = r - (r - l + 1) / 3; FORE(i, l, m1) res[x][i] = d; solve(d, l, m1, l - 1, r + 1, prv, d - 3); FORE(i, m1 + 1, m2) res[x][i] = d - 1; solve(d - 1, m1 + 1, m2, l - 1, r + 1, prv, d - 3); FORE(i, m2 + 1, r) res[x][i] = d - 2; solve(d - 2, m2 + 1, r, l - 1, r + 1, prv, d - 3); } else if (trace[d] == 2) { int m = l + r >> 1; FORE(i, l, m) res[x][i] = d; solve(d, l, m, l - 1, r + 1, prv, d - 2); FORE(i, m + 1, r) res[x][i] = d - 1; solve(d - 1, m + 1, r, l - 1, r + 1, prv, d - 2); } else { FORE(i, l, r) res[x][i] = d; solve(d, l, r, l - 1, r + 1, prv, d - 1); } }; solve(0, 1, dp[X], 1, dp[X], 0, X); REP(i, X + 1) res[i].resize(N + 1); return res; }

Compilation message (stderr)

prison.cpp: In lambda function:
prison.cpp:78:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |             int m = l + r >> 1;
      |                     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...