Submission #303241

#TimeUsernameProblemLanguageResultExecution timeMemory
303241VROOM_VARUNSecret (JOI14_secret)C++14
100 / 100
512 ms8388 KiB
/* ID: varunra2 LANG: C++ TASK: secret */ #include <bits/stdc++.h> using namespace std; #include "secret.h" #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e9 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions VI vals; int n; int cnt = 0; const int mxn = 1001; VVI dp(mxn, VI(mxn)); // int Secret(int x, int y) { // cnt++; // return min(x + 2 * (y / 2), INF); // } void work(int l, int r) { // do dnc here if (l >= r) return; int mid = (l + r) / 2; dp[mid][mid] = vals[mid]; dp[mid + 1][mid + 1] = vals[mid + 1]; for (int i = mid + 2; i <= r; i++) { dp[mid + 1][i] = Secret(dp[mid + 1][i - 1], vals[i]); } for (int i = mid - 1; i >= l; i--) { dp[mid][i] = Secret(vals[i], dp[mid][i + 1]); } work(l, mid); work(mid + 1, r); } void Init(int N, int a[]) { n = N; vals.resize(n); for (int i = 0; i < n; i++) { vals[i] = a[i]; } work(0, n - 1); } int Query(int l, int r) { int tl, tr; tl = 0; tr = n - 1; while (tl < tr) { int tm = (tl + tr) / 2; if (tm >= l and tm < r) return Secret(dp[tm][l], dp[tm + 1][r]); if (tm == r) return dp[tm][l]; if (tm < l) tl = tm + 1; else tr = tm; } return dp[tl][tl]; } // int main() { // #ifndef ONLINE_JUDGE // freopen("secret.in", "r", stdin); // freopen("secret.out", "w", stdout); // #endif // cin.sync_with_stdio(0); // cin.tie(0); // int n; // cin >> n; // int vals[n]; // for (int i = 0; i < n; i++) { // cin >> vals[i]; // } // Init(n, vals); // int q; // cin >> q; // while (q--) { // int l, r; // cin >> l >> r; // cout << Query(l, r) << '\n'; // } // for (int i = 0; i < mxn; i++) { // debug(i, dp[i]); // } // debug(cnt); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...