제출 #581083

#제출 시각아이디문제언어결과실행 시간메모리
581083MohammadAghil밀림 점프 (APIO21_jumps)C++17
0 / 100
1 ms300 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];

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;
}

int minimum_jumps(int a, int b, int c, int 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;
}

void init(int n, vector<int> H){
     rep(i,0,n) h[i+1] = H[i]; h[0] = h[n+1] = inf;
     vector<int> st;
     rep(i,1,n + 1){
          while(sz(st) && h[st.back()] < h[i]) st.pop_back();
          if(sz(st)) lx[i] = st.back();
          st.pb(i);
     } st.clear();
     per(i,n,1){
          while(sz(st) && h[st.back()] < h[i]) st.pop_back();
          rx[i] = n+1;
          if(sz(st)) rx[i] = st.back();
          st.pb(i);
     } st.clear();
}

// int main(){
//      cin.tie(0) -> sync_with_stdio(0);
//      int n; cin >> n;
//      rep(i,1,n+1) cin >> h[i]; h[0] = h[n+1] = inf;
//      vector<int> st;
//      rep(i,1,n + 1){
//           while(sz(st) && h[st.back()] < h[i]) st.pop_back();
//           if(sz(st)) lx[i] = st.back();
//           st.pb(i);
//      } st.clear();
//      per(i,n,1){
//           while(sz(st) && h[st.back()] < h[i]) st.pop_back();
//           rx[i] = n+1;
//           if(sz(st)) rx[i] = st.back();
//           st.pb(i);
//      } st.clear();
//      rep(i,1,n+1) er(i, lx[i], rx[i]); 
//      int q; cin >> q;
//      while(q--){
//           int a, b, c, d; cin >> a >> b >> c >> d; 
//           cout << minimum_jumps(++a, ++b, ++c, ++d) << '\n';
//      }
//      return 0; 
// }

컴파일 시 표준 에러 (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:45:6: note: in expansion of macro 'rep'
   45 |      rep(i,0,n) h[i+1] = H[i]; h[0] = h[n+1] = inf;
      |      ^~~
jumps.cpp:45:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |      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...