Submission #869906

#TimeUsernameProblemLanguageResultExecution timeMemory
869906borisAngelovPassport (JOI23_passport)C++17
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2505; int n, q; int l[maxn]; int r[maxn]; int dp[maxn][maxn]; int f(int from, int to) { if (from == 1 && to == n) { return 0; } if (dp[from][to] != 0) { return dp[from][to]; } int result = maxn; for (int pos = from; pos <= to; ++pos) { if (l[pos] < from || r[pos] > to) { result = min(result, 1 + f(min(from, l[pos]), max(to, r[pos]))); } } return dp[from][to] = result; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; for (int i = 1; i <= n; ++i) { cin >> l[i] >> r[i]; } cin >> q; for (int i = 1; i <= q; ++i) { int start; cin >> start; int ans = f(start, start); if (ans == 0) { cout << -1 << "\n"; } else { cout << ans << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...