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<utility>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> vec(n + 1);
for(int i = 1; i <= n; i++) cin >> vec[i].first >> vec[i].second;
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 1e9));
dp[1][n] = 0;
for(int l = n - 1; l > 0; l--){
for(int i = 1; i + l - 1 <= n; i++){
int j = i + l - 1;
for(int k = i; k <= j; k++){
dp[i][j] = min(dp[i][j], dp[min(i, vec[k].first)][max(j, vec[k].second)] + 1);
}
}
}
int q;
cin >> q;
while(q--){
int a;
cin >> a;
if(dp[a][a] == 1e9) cout << "-1\n";
else cout << dp[a][a] << "\n";
}
}
// g++ -std=gnu++20 pC.cpp -o run -Wall -Wextra -fsanitize=undefined -fsanitize=address
# | 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... |