This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |