/* 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];
int q; cin >> q;
for(int i = 1; i <= q; ++i){
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) dp[i][j] = MOD;
dp[1][n] = 0;
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Runtime error |
385 ms |
54156 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
1177 ms |
25428 KB |
Output is correct |
17 |
Correct |
492 ms |
25792 KB |
Output is correct |
18 |
Correct |
15 ms |
25944 KB |
Output is correct |
19 |
Correct |
22 ms |
25180 KB |
Output is correct |
20 |
Correct |
1820 ms |
26092 KB |
Output is correct |
21 |
Correct |
759 ms |
26196 KB |
Output is correct |
22 |
Correct |
7 ms |
25764 KB |
Output is correct |
23 |
Correct |
1220 ms |
25996 KB |
Output is correct |
24 |
Correct |
659 ms |
25904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
1177 ms |
25428 KB |
Output is correct |
17 |
Correct |
492 ms |
25792 KB |
Output is correct |
18 |
Correct |
15 ms |
25944 KB |
Output is correct |
19 |
Correct |
22 ms |
25180 KB |
Output is correct |
20 |
Correct |
1820 ms |
26092 KB |
Output is correct |
21 |
Correct |
759 ms |
26196 KB |
Output is correct |
22 |
Correct |
7 ms |
25764 KB |
Output is correct |
23 |
Correct |
1220 ms |
25996 KB |
Output is correct |
24 |
Correct |
659 ms |
25904 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
2087 ms |
25176 KB |
Time limit exceeded |
28 |
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 |
1 ms |
348 KB |
Output is correct |
4 |
Runtime error |
385 ms |
54156 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |