#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;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |