Submission #1084385

#TimeUsernameProblemLanguageResultExecution timeMemory
1084385BananabreadPassport (JOI23_passport)C++17
0 / 100
1 ms604 KiB
#include<bits/stdc++.h> #define ll long long #define ntr "\n" #define mod (ll)(1e9+7) #define taskname "" #define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); using namespace std; ll l[3001]; ll r[3001]; ll n; ll q; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //frep; cin>>n; for(int i=1;i<=n;i++){ cin>>l[i]>>r[i]; } ll dp[n+1][n+1]; ll vis[n+1][n+1]; cin>>q; for(int i=1;i<=q;i++){ ll x; cin>>x; memset(dp,0x3f,sizeof(dp)); memset(vis,0,sizeof(vis)); dp[l[x]][r[x]]=1; queue<pair<ll,ll>> q; q.push({l[x],r[x]}); while(!q.empty()){ ll lu=q.front().first,ru=q.front().second; q.pop(); if(vis[lu][ru]) continue; for(int i=lu;i<=ru;i++){ ll nl=min(lu,l[i]); ll nr=max(ru,r[i]); if(dp[nl][nr]>dp[lu][ru]+1){ dp[nl][nr]=dp[lu][ru]+1; } } } cout<<(dp[1][n]<=1e18 ? dp[1][n] : -1)<<ntr; } }
#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...