This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=105;
int a[N],n,q,k,dis[N];
bool vis[N];
vector<pair<int,int>> adj[N];
void dijkstra(int s){
for (int i=0;i<N;i++) dis[i]=INT_MAX,vis[i]=0;
dis[s]=0;
priority_queue<pair<int,int>> pq;
pq.push({0,s});
while (!pq.empty()){
int x=pq.top().S;
pq.pop();
if (vis[x]) continue;
vis[x]=1;
for (auto u:adj[x]){
if (dis[u.F]>dis[x]+u.S){
dis[u.F]=dis[x]+u.S;
pq.push({-dis[u.F],u.F});
}
}
}return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k>>q;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++){
for (int j=i+1;j<=n;j++){
int w=0;
for (int k=i+1;k<j;k++) w+=(a[k]>=min(a[i],a[j]));
adj[i].pb({j,w+1});
adj[j].pb({i,w+1});
}
}
while (q--){
int x,y;
cin>>x>>y;
dijkstra(x);
cout<<dis[y]-1<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |