# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874161 | LucaLucaM | Passport (JOI23_passport) | C++17 | 2072 ms | 21852 KiB |
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 <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#warning That's the baby, that's not my baby
typedef long long ll;
/**
ce cred eu ca se intampla defapt e ca mereu voi putea accesa un interval de tari
si atunci o sa am o dinamica de genu
dp[i][l] =def= care e cel mai din dreapta r la care pot ajunge dupa i operatii, a.i. am capatul din stanga pe pozitia l
**/
struct Country {
int l, r;
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
std::vector<Country> v(n + 1);
int rMax[n + 1] = {};
for (int i = 1; i <= n; i++) {
std::cin >> v[i].l >> v[i].r;
rMax[i] = std::max(rMax[i - 1], v[i].r);
}
int q;
std::cin >> q;
while (q--) {
int x;
std::cin >> x;
if (x == 1) {
int answer = 0;
while (x != n && rMax[x] > x) {
x = rMax[x];
answer++;
}
if (x != n) {
answer = -1;
}
std::cout << answer << '\n';
} else {
int dp[n + 2][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][x] = x;
for (int i = 0; i < n + 2; i++) {
for (int l = 1; l <= n; l++) {
for (int j = l; j <= dp[i][l]; j++) {
int newL = std::min(l, v[j].l);
dp[i + 1][newL] = std::max(dp[i + 1][newL], std::max(dp[i][l], v[j].r));
}
}
}
int answer = -1;
for (int i = 0; i < n + 2 && answer == -1; i++) {
if (dp[i][1] == n) {
answer = i;
}
}
std::cout << answer << '\n';
}
}
return 0;
}
Compilation message (stderr)
# | 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... |