#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=305;
int dp[N][N],L[N],R[N],n,q;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<=n;i++) cin>>L[i]>>R[i];
for (int i=1;i<=n;i++) for (int j=i;j<=n;j++) dp[i][j]=INT_MAX;
dp[1][n]=0;
for (int len=n-2;len>=0;len--){
for (int l=1;l+len<=n;l++){
int r=l+len;
for (int k=l;k<=r;k++){
int l1=min(L[k],l),r1=max(R[k],r);
dp[l][r]=min(dp[l][r],dp[l1][r1]+1);
}
}
}
cin>>q;
while (q--){
int x;cin>>x;
if (dp[x][x]>=INT_MAX) cout<<-1<<endl;
else cout<<dp[x][x]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
11 ms |
3348 KB |
Execution killed with signal 11 |
5 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
10 ms |
1116 KB |
Output is correct |
12 |
Correct |
10 ms |
1116 KB |
Output is correct |
13 |
Correct |
9 ms |
1116 KB |
Output is correct |
14 |
Correct |
9 ms |
1156 KB |
Output is correct |
15 |
Correct |
12 ms |
1192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
10 ms |
1116 KB |
Output is correct |
12 |
Correct |
10 ms |
1116 KB |
Output is correct |
13 |
Correct |
9 ms |
1116 KB |
Output is correct |
14 |
Correct |
9 ms |
1156 KB |
Output is correct |
15 |
Correct |
12 ms |
1192 KB |
Output is correct |
16 |
Runtime error |
2 ms |
1880 KB |
Execution killed with signal 11 |
17 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
10 ms |
1116 KB |
Output is correct |
12 |
Correct |
10 ms |
1116 KB |
Output is correct |
13 |
Correct |
9 ms |
1116 KB |
Output is correct |
14 |
Correct |
9 ms |
1156 KB |
Output is correct |
15 |
Correct |
12 ms |
1192 KB |
Output is correct |
16 |
Runtime error |
2 ms |
1880 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
11 ms |
3348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |