#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int dp[2501][2501];
int n;
vector<pair<int,int>> v;
int solve(int l,int r){
if(l == 0 && r == n-1) return 0;
int &ret = dp[l][r];
if(~ret) return ret;
ret = 1e9;
for(int i=l;i<=r;i++){
int L = min(l , v[i].first);
int R = max(r , v[i].second);
if(l == L && r == R) continue;
ret = min(ret , solve(L,R) + 1);
}
return ret;
}
void solve(){
cin>>n;
v.resize(n);
for(auto &[a,b] : v) cin>>a>>b , a -- , b--;
memset(dp,-1,sizeof(dp));
int q;
cin>>q;
while(q--){
int x;
cin>>x;
x --;
int ans = solve(x,x);
cout<<(ans >= 1e9 ? -1 : ans)<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message
passport.cpp: In function 'void solve()':
passport.cpp:24:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | for(auto &[a,b] : v) cin>>a>>b , a -- , b--;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
4 ms |
24924 KB |
Output is correct |
4 |
Execution timed out |
2068 ms |
28744 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24788 KB |
Output is correct |
3 |
Correct |
4 ms |
24924 KB |
Output is correct |
4 |
Correct |
4 ms |
24920 KB |
Output is correct |
5 |
Correct |
4 ms |
24924 KB |
Output is correct |
6 |
Correct |
4 ms |
24784 KB |
Output is correct |
7 |
Correct |
4 ms |
24924 KB |
Output is correct |
8 |
Correct |
4 ms |
24924 KB |
Output is correct |
9 |
Correct |
4 ms |
24784 KB |
Output is correct |
10 |
Correct |
4 ms |
24924 KB |
Output is correct |
11 |
Correct |
5 ms |
24924 KB |
Output is correct |
12 |
Correct |
5 ms |
24756 KB |
Output is correct |
13 |
Correct |
4 ms |
24924 KB |
Output is correct |
14 |
Correct |
4 ms |
24924 KB |
Output is correct |
15 |
Correct |
5 ms |
24924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24788 KB |
Output is correct |
3 |
Correct |
4 ms |
24924 KB |
Output is correct |
4 |
Correct |
4 ms |
24920 KB |
Output is correct |
5 |
Correct |
4 ms |
24924 KB |
Output is correct |
6 |
Correct |
4 ms |
24784 KB |
Output is correct |
7 |
Correct |
4 ms |
24924 KB |
Output is correct |
8 |
Correct |
4 ms |
24924 KB |
Output is correct |
9 |
Correct |
4 ms |
24784 KB |
Output is correct |
10 |
Correct |
4 ms |
24924 KB |
Output is correct |
11 |
Correct |
5 ms |
24924 KB |
Output is correct |
12 |
Correct |
5 ms |
24756 KB |
Output is correct |
13 |
Correct |
4 ms |
24924 KB |
Output is correct |
14 |
Correct |
4 ms |
24924 KB |
Output is correct |
15 |
Correct |
5 ms |
24924 KB |
Output is correct |
16 |
Correct |
1422 ms |
25168 KB |
Output is correct |
17 |
Correct |
689 ms |
24924 KB |
Output is correct |
18 |
Correct |
15 ms |
24920 KB |
Output is correct |
19 |
Correct |
26 ms |
24920 KB |
Output is correct |
20 |
Execution timed out |
2053 ms |
24924 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24788 KB |
Output is correct |
3 |
Correct |
4 ms |
24924 KB |
Output is correct |
4 |
Correct |
4 ms |
24920 KB |
Output is correct |
5 |
Correct |
4 ms |
24924 KB |
Output is correct |
6 |
Correct |
4 ms |
24784 KB |
Output is correct |
7 |
Correct |
4 ms |
24924 KB |
Output is correct |
8 |
Correct |
4 ms |
24924 KB |
Output is correct |
9 |
Correct |
4 ms |
24784 KB |
Output is correct |
10 |
Correct |
4 ms |
24924 KB |
Output is correct |
11 |
Correct |
5 ms |
24924 KB |
Output is correct |
12 |
Correct |
5 ms |
24756 KB |
Output is correct |
13 |
Correct |
4 ms |
24924 KB |
Output is correct |
14 |
Correct |
4 ms |
24924 KB |
Output is correct |
15 |
Correct |
5 ms |
24924 KB |
Output is correct |
16 |
Correct |
1422 ms |
25168 KB |
Output is correct |
17 |
Correct |
689 ms |
24924 KB |
Output is correct |
18 |
Correct |
15 ms |
24920 KB |
Output is correct |
19 |
Correct |
26 ms |
24920 KB |
Output is correct |
20 |
Execution timed out |
2053 ms |
24924 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
4 ms |
24924 KB |
Output is correct |
4 |
Execution timed out |
2068 ms |
28744 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |