# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
287636 | 2020-08-31T21:42:47 Z | jainbot27 | Secret (JOI14_secret) | C++17 | 546 ms | 8440 KB |
//author: JainBot27 //Created on: 08/31/20 #pragma GCC optimize("Ofast") #pragma GCC target("sse4,avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define ts to_string #define ub upper_bound #define lb lower_bound #define ar array #define all(x) x.begin(), x.end() #define siz(x) (int)x.size() #define FOR(x, y, z) for(int x = (y); x < (z); x++) #define ROF(x, y, z) for(int x = (y-1); x >= (z); x--) #define F0R(x, z) FOR(x, 0, z) #define R0F(x, z) ROF(x, z, 0) #define trav(x, y) for(auto&x:y) const string nl = "\n"; using ll = int64_t; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; using vpii = vector<pii>; using vpll = vector<pll>; template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;} template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); str ts(char c) { return str(1,c); } str ts(bool b) { return b ? "true" : "false"; } str ts(const char* s) { return (str)s; } str ts(str s) { return s; } template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); } str ts(vector<bool> v) { str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]); res += "}"; return res; } template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]); return res; } template<class A, class B> str ts(pair<A,B> p); template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) { if (!fst) res += ", "; fst = 0; res += ts(x); } res += "}"; return res; } template<class A, class B> str ts(pair<A,B> p) { return "("+ts(p.f)+", "+ts(p.s)+")"; } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef D #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif #include "secret.h" int a[1001], n, dp[1001][1001]; //int secret(int a, int b){ //return -69; //} void go(int l = 0, int r = n-1){ int m = (l + r)/2; dp[m][m]=a[m]; dp[m+1][m+1]=a[m+1]; ROF(i,m,l){ dp[m][i] = Secret(a[i], dp[m][i+1]); } //for(int i=m-1; i >= l; i--){ //dp[m][i] = Secret(dp[m][i+1], a[i]); //} FOR(i,m+2,r+1){ dp[m+1][i] = Secret(dp[m+1][i-1], a[i]); } if(l<m)go(l,m); if(m+1<r)go(m+1,r); } void Init(int N, int A[]){ F0R(i, N) a[i]=A[i]; n=N; go(); } int Query(int A, int B){ int l = 0, r = n-1; while(l != r){ int m = (l + r)/2; if(m==B){ return dp[m][A]; } else if(m >= A && m < B){ return Secret(dp[m][A], dp[m+1][B]); } else if(m < A){ l = m + 1; } else{ r = m; } } return dp[l][r]; } /* int main(){ int n; cin >> n; int x[8]; for(int i=0; i < n; i++){ cin >> x[i]; } Init(n, x); int q; cin >> q; for(int i =0; i < q; i++){ int c, v; cin >> c >> v; cout << Query(c,v) << nl; } } /* * Stuff I should try: * Is it Monotonic? -> Binary Search * Is N small? -> Bitsets or other exponential * Edge Cases? Look Carefully * Can't figure anything out? Brute Force and see patterns * Try to prove greedies * Prefix Sums, Amortization, DP, Data Structures */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 148 ms | 4472 KB | Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 | Correct | 153 ms | 4584 KB | Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 | Correct | 151 ms | 4600 KB | Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 | Correct | 529 ms | 8300 KB | Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 | Correct | 524 ms | 8312 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 | Correct | 529 ms | 8432 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 | Correct | 528 ms | 8300 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 | Correct | 522 ms | 8440 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 | Correct | 546 ms | 8304 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 | Correct | 528 ms | 8312 KB | Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |