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 maxn=3000;
int dp[2510][2510],n,q;
pair<int,int> ori[2510];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>ori[i].first>>ori[i].second;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)dp[i][j]=maxn;
}
dp[1][n]=0;
for(int i=1;i<=n;i++){
for(int j=n;j>=i;j--){
for(int k=i;k<=j;k++){
dp[i][j]=min(dp[i][j],dp[min(i,ori[k].first)][max(j,ori[k].second)]+1);
}
}
}
cin>>q;
for(int i=1;i<=q;i++){
int x;
cin>>x;
if(dp[x][x]==maxn){
cout<<"-1\n";
}else{
cout<<dp[x][x]<<"\n";
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |