Submission #581165

#TimeUsernameProblemLanguageResultExecution timeMemory
581165MohammadAghilRainforest Jumps (APIO21_jumps)C++17
8 / 100
4062 ms4380 KiB
#include <bits/stdc++.h> #include "jumps.h" // #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<int, int> pp; #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 1e9 + 7, maxn = 5e5 + 5, lg = 22, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;} int h[maxn], lx[maxn], rx[maxn], n; int query(int a, int b){ if(h[a] > h[b]) return inf; // int cr = a, cnt = -1; // while(true){ // cnt++; // if(cr == b) return cnt; // bool okl = h[lx[cr]] <= h[b], okr = h[rx[cr]] <= h[b]; // if(okl && okr) cr = h[lx[cr]] > h[rx[cr]]? lx[cr]: rx[cr]; // else if(okl) cr = lx[cr]; // else if(okr) cr = rx[cr]; // else return inf; // } // return inf; deque<int> q{a}; vector<int> dist(n + 2, inf); dist[a] = 0; while(sz(q)){ int r = q.front(); q.pop_front(); if(h[r] > h[b]) continue; if(r == b) return dist[r]; if(lx[r] > 0 && dist[lx[r]] == inf) q.push_back(lx[r]), dist[lx[r]] = dist[r] + 1; if(rx[r] < n+1 && dist[rx[r]] == inf) q.push_back(rx[r]), dist[rx[r]] = dist[r] + 1; } return inf; } int minimum_jumps(int a, int b, int c, int d){ a++, b++, c++, d++; int ans = inf; rep(i,a,b+1) rep(j,c,d+1) ans = min(ans, query(i, j)); return ans == inf? -1: ans; // return c - b; } void init(int n, vector<int> H){ ::n = n; rep(i,0,n) h[i+1] = H[i]; h[0] = h[n+1] = inf; vector<int> st = {0}; rep(i,1,n + 1){ while(h[st.back()] < h[i]) st.pop_back(); lx[i] = st.back(), st.pb(i); } st = {n+1}; per(i,n,1){ while(h[st.back()] < h[i]) st.pop_back(); rx[i] = st.back(), st.pb(i); } } // int main(){ // cin.tie(0) -> sync_with_stdio(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); // int n; cin >> n; ::n = n; // int q; cin >> q; // rep(i,1,n+1) cin >> h[i]; h[0] = h[n+1] = inf; // vector<int> st = {0}; // rep(i,1,n + 1){ // while(h[st.back()] < h[i]) st.pop_back(); // lx[i] = st.back(), st.pb(i); // } st = {n+1}; // per(i,n,1){ // while(h[st.back()] < h[i]) st.pop_back(); // rx[i] = st.back(), st.pb(i); // } // while(q--){ // int a, b, c, d; cin >> a >> b >> c >> d; // cout << minimum_jumps(a, b, c, d) << '\n'; // } // return 0; // }

Compilation message (stderr)

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:10:28: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   10 |         #define rep(i,l,r) for(int i = (l); i < (r); i++)
      |                            ^~~
jumps.cpp:56:6: note: in expansion of macro 'rep'
   56 |      rep(i,0,n) h[i+1] = H[i]; h[0] = h[n+1] = inf;
      |      ^~~
jumps.cpp:56:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   56 |      rep(i,0,n) h[i+1] = H[i]; h[0] = h[n+1] = inf;
      |                                ^
#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...