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>
using namespace std;
const int mxN=100;
int n, k, q, l[mxN], d[mxN][mxN];
vector<int> adj[mxN];
queue<int> qu;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> q;
for(int i=0; i<n; ++i) {
cin >> l[i];
int mx=0;
for(int j=i-1; ~j; --j) {
if(mx<l[i]&&mx<l[j]) {
adj[i].push_back(j);
adj[j].push_back(i);
}
mx=max(l[j], mx);
}
}
memset(d, 0x3f, sizeof(d));
for(int i=0; i<n; ++i) {
d[i][i]=0;
qu.push(i);
while(qu.size()) {
int u=qu.front();
qu.pop();
for(int v : adj[u]) {
if(d[i][v]>d[i][u]+1) {
d[i][v]=d[i][u]+1;
qu.push(v);
}
}
}
}
for(int a, b; q--; ) {
cin >> a >> b, --a, --b;
cout << d[a][b]-1 << "\n";
}
}
# | 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... |