This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2500+100, M = 1e5+10, K = 21;
int n;
map<int, int> dp[N];
array<int, 2> a[N];
int dfs(int l, int r){
if(dp[l].find(r) != dp[l].end()) return dp[l][r];
int val = MOD;
for(int i = l; i <= r; ++i){
int L = min(l, a[i][0]);
int R = max(r, a[i][1]);
if(R > r || L < l)
val = min(val, dfs(L, R) + 1);
}
return dp[l][r] = val;
}
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i][0] >> a[i][1];
dp[1][n] = 0;
int q; cin >> q;
for(int i = 1; i <= q; ++i){
int v; cin >> v;
int ans = dfs(v, v);
cout << (ans == MOD ? -1 : ans) << '\n';
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
passport.cpp: In function 'int main()':
passport.cpp:42:15: warning: unused variable 'aa' [-Wunused-variable]
42 | int tt = 1, aa;
| ^~
# | 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... |