Submission #428749

#TimeUsernameProblemLanguageResultExecution timeMemory
428749hhhhauraRainforest Jumps (APIO21_jumps)C++14
0 / 100
4034 ms15208 KiB
#define wiwihorz #include "jumps.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define ceil(a, b) ((a + b - 1) / (b)) #define all(x) x.begin(), x.end() #define MOD 1000000007 #define eps (1e-9) #define INF 1000000000 using namespace std; #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; } void kout() {cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);} #else #define print(...) 0 #define vprint(...) 0 #endif int n; vector<int> L, R, d, h; void init(int N, vector<int> H) { n = N, h = H; set<int> s; vector<int> a(n, 0); L.assign(n, -1); R.assign(n, -1); d.assign(n, 0); rep(i, 0, n - 1) a[i] = i; sort(all(a), [](int x, int y) { return h[x] > h[y]; }); for(auto i : a) { auto it = s.lower_bound(i); if(it != s.end()) { d[i] = d[*it] + 1; R[i] = *it; } if(it != s.begin()) { it = prev(it); L[i] = *it; } s.insert(i); } // vprint(all(L)); // vprint(all(R)); // vprint(all(d)); return; } /* 7 3 3 2 1 6 4 5 7 4 4 6 6 1 3 5 6 0 1 2 2 */ int minimum_jumps(int A, int B, int C, int D) { int to = C, from = -1; rep(i, C, D) if(h[i] > h[to]) to = i; rep(i, A, B) if(h[i] < h[to]) { if(from == -1 || h[from] < h[i]) from = i; } if(from == -1) return -1; rep(i, from, to) if(h[i] > h[to]) return -1; int cnt = 0, cur = 0, id = from, ans = INF; while(id != -1) { if(h[id] > h[to]) break; cur = id; while(cur < C) cur = R[cur]; ans = min(ans, cnt + d[id] - d[cur]); cnt ++, id = L[id]; } return ans; }

Compilation message (stderr)

jumps.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
jumps.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
jumps.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
#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...