# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
804664 | thimote75 | Passport (JOI23_passport) | C++14 | 2074 ms | 53964 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 <bits/stdc++.h>
using namespace std;
using di = pair<int, int>;
using vd = vector<di>;
vd dis;
const int MAXN = 2600;
int dp[MAXN][MAXN];
int _compute (int l, int r) {
if (l == 0 && r == dis.size() - 1) return 0;
if (dp[l][r] != -1) return dp[l][r];
dp[l][r] = 1e9;
for (int i = l; i <= r; i ++) {
dp[l][r] = min(
dp[l][r],
_compute(min(l, dis[i].first), max(r, dis[i].second)) + 1
);
}
return dp[l][r];
}
int compute (int l, int r) {
return _compute(l, r) >= 1e9 ? -1 : _compute(l, r);
}
int main () {
int N;
cin >> N;
for (int i = 0; i < N; i ++)
for (int j = 0; j < N; j ++)
dp[i][j] = -1;
dis = vd(N);
for (int i = 0; i < N; i ++) {
int l, r;
cin >> l >> r;
l --;
r --;
dis[i] = { l, r };
}
int Q; cin >> Q;
for (int i = 0; i < Q; i ++) {
int x; cin >> x;
x --;
cout << compute(x, x) << "\n";
}
}
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... |