Submission #793818

#TimeUsernameProblemLanguageResultExecution timeMemory
793818vjudge1Passport (JOI23_passport)C++17
16 / 100
2075 ms5652 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 3010; const int INF = 1e9; int dp[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n; cin >> n; int L[n + 1], R[n + 1]; for(int i = 1; i <= n; i++) cin >> L[i] >> R[i]; dp[1][n] = 0; for(int len = n - 1; len >= 1; len--) { for(int l = 1; l <= n - len + 1; l++) { int r = l + len - 1; dp[l][r] = INF; for(int i = l; i <= r; i++) { dp[l][r] = min(dp[l][r], dp[min(l, L[i])][max(r, R[i])] + 1); } } } int q; cin >> q; while(q--) { int x; cin >> x; cout << (dp[x][x] == INF ? -1 : dp[x][x]) << '\n'; } }
#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...