#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define isz(a) (int)(a).size()
const int NM = 2500, inf = 1e9+7;
int ntest = 1;
int N, L[NM+5], R[NM+5], Q, dp[NM+5][NM+5];
void solve(){
cin >> N;
for (int i = 1; i <= N; i++)
cin >> L[i] >> R[i];
cin >> Q;
while (Q--){
int X; cin >> X;
for (int i = 1; i <= N; i++)
for (int j = i; j <= N; j++) dp[i][j] = +inf;
dp[X][X] = 0;
for (int i = N; i >= 1; i--)
for (int j = i; j <= N; j++){
if (dp[i][j] == +inf) continue;
for (int k = i; k <= j; k++)
if (L[k] < i || R[k] > j) dp[min(i, L[k])][max(j, R[k])] = min(dp[min(i, L[k])][max(j, R[k])], dp[i][j]+1);
}
cout << (dp[1][N] == +inf ? -1 : dp[1][N]) << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//cin >> ntest;
while (ntest--){
solve();
}
#ifdef daoquanglinh2007
cout << '\n';
for (int i = 1; i <= 100; i++) cout << '=';
cout << "\nExecution time: " << 1*(clock()) << " ms\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
23 ms |
31172 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
0 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
2 ms |
1640 KB |
Output is correct |
12 |
Correct |
2 ms |
1640 KB |
Output is correct |
13 |
Correct |
1 ms |
1640 KB |
Output is correct |
14 |
Correct |
1 ms |
1640 KB |
Output is correct |
15 |
Correct |
2 ms |
1640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
0 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
2 ms |
1640 KB |
Output is correct |
12 |
Correct |
2 ms |
1640 KB |
Output is correct |
13 |
Correct |
1 ms |
1640 KB |
Output is correct |
14 |
Correct |
1 ms |
1640 KB |
Output is correct |
15 |
Correct |
2 ms |
1640 KB |
Output is correct |
16 |
Correct |
660 ms |
19048 KB |
Output is correct |
17 |
Correct |
379 ms |
20584 KB |
Output is correct |
18 |
Correct |
22 ms |
20584 KB |
Output is correct |
19 |
Correct |
22 ms |
20072 KB |
Output is correct |
20 |
Correct |
1182 ms |
20724 KB |
Output is correct |
21 |
Correct |
509 ms |
20572 KB |
Output is correct |
22 |
Correct |
11 ms |
20572 KB |
Output is correct |
23 |
Correct |
622 ms |
20704 KB |
Output is correct |
24 |
Correct |
317 ms |
20572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
0 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
2 ms |
1640 KB |
Output is correct |
12 |
Correct |
2 ms |
1640 KB |
Output is correct |
13 |
Correct |
1 ms |
1640 KB |
Output is correct |
14 |
Correct |
1 ms |
1640 KB |
Output is correct |
15 |
Correct |
2 ms |
1640 KB |
Output is correct |
16 |
Correct |
660 ms |
19048 KB |
Output is correct |
17 |
Correct |
379 ms |
20584 KB |
Output is correct |
18 |
Correct |
22 ms |
20584 KB |
Output is correct |
19 |
Correct |
22 ms |
20072 KB |
Output is correct |
20 |
Correct |
1182 ms |
20724 KB |
Output is correct |
21 |
Correct |
509 ms |
20572 KB |
Output is correct |
22 |
Correct |
11 ms |
20572 KB |
Output is correct |
23 |
Correct |
622 ms |
20704 KB |
Output is correct |
24 |
Correct |
317 ms |
20572 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 |
2077 ms |
19804 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
23 ms |
31172 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |