/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2500+100, M = 1e5+10, K = 21;
int n, dp[N][N];
array<int, 2> a[N];
int dfs(int l, int r){
if(dp[l][r] != MOD) return dp[l][r];
for(int i = l; i <= r; ++i){
int L = min(l, a[i][0]);
int R = max(r, a[i][1]);
if(R > r || L < l)
dp[l][r] = min(dp[l][r], dfs(L, R) + 1);
}
return dp[l][r];
}
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i][0] >> a[i][1];
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) dp[i][j] = MOD;
dp[1][n] = 0;
int q; cin >> q;
for(int i = 1; i <= q; ++i){
int v; cin >> v;
int ans = dfs(v, v);
cout << (ans == MOD ? -1 : ans) << '\n';
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message
passport.cpp: In function 'int main()':
passport.cpp:41:15: warning: unused variable 'aa' [-Wunused-variable]
41 | int tt = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Runtime error |
200 ms |
54176 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
2 ms |
4668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
2 ms |
4668 KB |
Output is correct |
16 |
Correct |
1203 ms |
25428 KB |
Output is correct |
17 |
Correct |
486 ms |
25792 KB |
Output is correct |
18 |
Correct |
14 ms |
25944 KB |
Output is correct |
19 |
Correct |
21 ms |
25176 KB |
Output is correct |
20 |
Correct |
1569 ms |
26108 KB |
Output is correct |
21 |
Correct |
722 ms |
26096 KB |
Output is correct |
22 |
Correct |
6 ms |
25688 KB |
Output is correct |
23 |
Correct |
1226 ms |
25996 KB |
Output is correct |
24 |
Correct |
597 ms |
26160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
2 ms |
4668 KB |
Output is correct |
16 |
Correct |
1203 ms |
25428 KB |
Output is correct |
17 |
Correct |
486 ms |
25792 KB |
Output is correct |
18 |
Correct |
14 ms |
25944 KB |
Output is correct |
19 |
Correct |
21 ms |
25176 KB |
Output is correct |
20 |
Correct |
1569 ms |
26108 KB |
Output is correct |
21 |
Correct |
722 ms |
26096 KB |
Output is correct |
22 |
Correct |
6 ms |
25688 KB |
Output is correct |
23 |
Correct |
1226 ms |
25996 KB |
Output is correct |
24 |
Correct |
597 ms |
26160 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1661 ms |
25252 KB |
Output is correct |
28 |
Correct |
1018 ms |
25976 KB |
Output is correct |
29 |
Execution timed out |
2047 ms |
26092 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Runtime error |
200 ms |
54176 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |