제출 #972429

#제출 시각아이디문제언어결과실행 시간메모리
972429dubabuba밀림 점프 (APIO21_jumps)C++14
0 / 100
141 ms78072 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; template<typename T> void ono_min(T &MIN, T CMP) { if(MIN > CMP) MIN = CMP; } template<typename T> void ono_max(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; } typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair const int mxk = 32; const int mxn = 2e5 + 10; int L[mxn], h[mxn]; int R[mxn], n; vector<int> adj[mxn]; int mx[mxk][mxn], mn[mxk][mxn]; pii ll[mxk][mxn], rr[mxk][mxn]; pii str[mxn * 4]; void build(int id, int tl, int tr) { if(tl == tr) { str[id] = MP(h[tl], tl); return; } int tm = (tl + tr) / 2; build(id * 2 + 1, tl, tm); build(id * 2 + 2, tm + 1, tr); str[id] = max(str[id * 2 + 1], str[id * 2 + 2]); // cout << tl << ' ' << tr << " = " << str[id].ff << endl; } pii query(int id, int tl, int tr, int l, int r) { if(l > r) return MP(0, -1); if(tl == l && r == tr) return str[id]; int tm = (tl + tr) / 2; if(r <= tm) return query(id * 2 + 1, tl, tm, l, r); if(tm < l) return query(id * 2 + 2, tm + 1, tr, l, r); pii LQ = query(id * 2 + 1, tl, tm, l, tm); pii RQ = query(id * 2 + 2, tm + 1, tr, tm + 1, r); return max(LQ, RQ); } void init(int N, vector<int> H) { memset(L, -1, sizeof L); memset(R, -1, sizeof R); n = N; stack<int> st; st.push(0); for(int i = 1; i < N; i++) { while(st.size() && H[st.top()] <= H[i]) st.pop(); if(st.size()) L[i] = st.top(); st.push(i); } stack<int> en; en.push(0); for(int i = N - 1; i >= 0; i--) { while(en.size() && H[en.top()] <= H[i]) en.pop(); if(en.size()) R[i] = en.top(); en.push(i); } for(int i = 0; i < N; i++) { h[i] = H[i]; if(L[i] > -1) { adj[i].push_back(L[i]); if(mn[0][H[i]] == 0) mn[0][H[i]] = H[L[i]]; ono_min(mn[0][H[i]], H[L[i]]); ono_max(mx[0][H[i]], H[L[i]]); ll[0][i] = MP(H[L[i]], L[i]); } if(R[i] > -1) { adj[i].push_back(R[i]); if(mn[0][H[i]] == 0) mn[0][H[i]] = H[R[i]]; ono_min(mn[0][H[i]], H[R[i]]); ono_max(mx[0][H[i]], H[R[i]]); rr[0][i] = MP(H[R[i]], R[i]); } } for(int k = 1; k < mxk; k++) for(int i = 1; i <= n; i++) { int mnj = mn[k - 1][i]; int mxj = mx[k - 1][i]; if(mnj) mn[k][i] = mn[k - 1][mnj]; if(mxj) mx[k][i] = mx[k - 1][mxj]; } for(int k = 1; k < mxk; k++) for(int i = 0; i < n; i++) { pii pl = ll[k - 1][i]; pii pr = rr[k - 1][i]; if(pl.ss) ll[k][i] = ll[k - 1][pl.ss]; if(pr.ss) rr[k][i] = rr[k - 1][pr.ss]; } // for(int i = 0; i < n; i++) // for(int k = 0; (1 << k) <= n; k++) // cout << i << ' ' << k << ": " << rr[k][i].ff << ' ' << rr[k][i].ss << endl; build(0, 0, n - 1); } int solve(int s, int f) { int ans = 0; for(int k = mxk - 1; k >= 0; k--) if(mx[k][s] && mx[k][s] <= f) { s = mx[k][s]; ans += (1 << k); } for(int k = mxk - 1; k >= 0; k--) if(mn[k][s] && mn[k][s] <= f) { s = mn[k][s]; ans += (1 << k); } if(s == f) return ans; return -1; } int minimum_jumps(int A, int B, int C, int D) { pii bet = query(0, 0, n - 1, B + 1, C - 1); // between int bet_mx = bet.ff; int bet_id = bet.ss; // cout << bet_id << ' ' << bet_mx << endl; // return -1; int l = B; for(int i = mxk - 1; i >= 0; i--) { pii p = ll[i][l]; int hi = p.ff; int id = p.ss; if(hi == 0) continue; if(hi > bet_mx) continue; if(id < A) continue; l = id; } int r = C; for(int i = mxk - 1; i >= 0; i--) { pii p = rr[i][r]; int hi = p.ff; int id = p.ss; if(hi == 0) continue; if(hi < bet_mx) continue; if(D < id) continue; r = id; } if(h[r] < bet_mx) return -1; if(h[l] > bet_mx) return solve(h[l], h[r]); int ans = solve(h[l], h[r]); int tmp = INT_MAX; if(L[l]) tmp = solve(h[L[l]], h[r]); if(tmp == -1) return ans; return min(ans, tmp); }

컴파일 시 표준 에러 (stderr) 메시지

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:134:6: warning: unused variable 'bet_id' [-Wunused-variable]
  134 |  int bet_id = bet.ss;
      |      ^~~~~~
#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...