Submission #851501

#TimeUsernameProblemLanguageResultExecution timeMemory
851501owoovoPassport (JOI23_passport)C++14
16 / 100
2037 ms50560 KiB
#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 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...