#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
std::cin >> n;
std::vector<ll> l(n + 1), r(n + 1);
for (ll i = 1; i <= n; ++i) {
std::cin >> l[i] >> r[i];
}
ll q;
std::cin >> q;
while (q--) {
ll x;
std::cin >> x;
std::vector dp(n + 1, std::vector<ll>(n + 1, 1e15));
dp[x][x] = 0;
for (ll len = 1; len <= n; ++len) {
for (ll i = 1; i + len - 1 <= n; ++i) {
for (ll j = i; j <= i + len - 1; ++j) {
ll _l = std::min(i, l[j]);
ll _r = std::max(i + len - 1, r[j]);
dp[_l][_r] = std::min(dp[_l][_r], dp[i][i + len - 1] + 1);
}
}
}
std::cout << (dp[1][n] == ll(1e15) ? -1 : dp[1][n]) << '\n';
}
}
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
507 ms |
1048576 KB |
Execution killed with signal 9 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
860 KB |
Output is correct |
12 |
Correct |
15 ms |
1164 KB |
Output is correct |
13 |
Correct |
11 ms |
1116 KB |
Output is correct |
14 |
Correct |
10 ms |
1116 KB |
Output is correct |
15 |
Correct |
16 ms |
1184 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
860 KB |
Output is correct |
12 |
Correct |
15 ms |
1164 KB |
Output is correct |
13 |
Correct |
11 ms |
1116 KB |
Output is correct |
14 |
Correct |
10 ms |
1116 KB |
Output is correct |
15 |
Correct |
16 ms |
1184 KB |
Output is correct |
16 |
Execution timed out |
2048 ms |
43344 KB |
Time limit exceeded |
17 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
860 KB |
Output is correct |
12 |
Correct |
15 ms |
1164 KB |
Output is correct |
13 |
Correct |
11 ms |
1116 KB |
Output is correct |
14 |
Correct |
10 ms |
1116 KB |
Output is correct |
15 |
Correct |
16 ms |
1184 KB |
Output is correct |
16 |
Execution timed out |
2048 ms |
43344 KB |
Time limit exceeded |
17 |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
507 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |