제출 #1055452

#제출 시각아이디문제언어결과실행 시간메모리
1055452KasymK밀림 점프 (APIO21_jumps)C++17
21 / 100
4074 ms14400 KiB
#include "bits/stdc++.h" #include "jumps.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 2e5+5; vector<int> adj[N]; int vis[N]; int n_; void init(int n, vector<int> v){ n_ = n; for(int i = 0; i < n; ++i){ for(int j = i+1; j < n; ++j) if(v[j] > v[i]){ adj[i].pb(j); break; } for(int j = i-1; j >= 0; --j) if(v[j] > v[i]){ adj[i].pb(j); break; } } } int minimum_jumps(int a, int b, int c, int d){ for(int i = 0; i <= n_; ++i) vis[i] = 0; queue<pii> q; for(int ad = a; ad <= b; ++ad){ q.push({ad, 0}); vis[ad] = 1; } while(!q.empty()){ auto x = q.front(); q.pop(); if(x.ff >= c and x.ff <= d) return x.ss; for(auto i : adj[x.ff]) if(!vis[i]){ q.push({i, x.ss+1}); vis[i] = 1; } } return -1; } // int main(){ // int n, q; // scanf("%d%d", &n, &q); // vector<int> h; // for(int i = 0; i < n; ++i){ // int x; // scanf("%d", &x); // h.pb(x); // } // init(n, h); // while(q--){ // int a, b, c, d; // scanf("%d%d%d%d", &a, &b, &c, &d); // int answer = minimum_jumps(a, b, c, d); // printf("%d\n", answer); // } // return 0; // }
#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...