Submission #1145437

#TimeUsernameProblemLanguageResultExecution timeMemory
1145437cleptopodPassport (JOI23_passport)C++20
0 / 100
496 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "deb.h" #else #define debug(...) #endif const int inf = 1e9; void solve() { int n; cin >> n; vector<int> l(n), r(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; --l[i]; --r[i]; } vector<vector<int>> dp(n, vector<int>(n, inf)); int q; cin >> q; while (q--) { int x; cin >> x; --x; dp[l[x]][r[x]] = 1; for (int length = 1; length <= n; length++) { for (int i = 0; i < n - length + 1; i++) { for (int j = i; j <= i + length - 1; j++) { dp[min(i, l[j])][max(i, r[j])] = min(dp[min(i, l[j])][max(i, r[j])], dp[i][i + length - 1] + 1); } } } cout << ((dp[0][n - 1] == inf) ? -1 : dp[0][n - 1]) << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } 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...