#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 = l[j];
ll _r = 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 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |