#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=2505;
const int INF=1e9;
inline int id(int a,int b){
return a*N+b;
}
int32_t main() {
LCBorz;
int n;cin>>n;
vector<int> adj[N*N],dis(N*N,INF);
vector<int> b(N),c(N);
for(int i=1;i<=n;i++){
cin>>b[i]>>c[i];
for(int j=1;j<=i;j++){
for(int k=i;k<=n;k++){
adj[id(j,k)].push_back(id(min(b[i],j),max(c[i],k)));
//cout<<id(j,k)<<' '<<id(min(b[i],j),max(c[i],k))<<endl;
}
}
}
int q1;cin>>q1;
int p;cin>>p;
queue<int> q;
q.push(id(b[p],c[p]));
dis[id(b[p],c[p])]=1;
while(q.size()){
int p=q.front();
q.pop();
for(int j:adj[p]){
if(dis[j]==INF){
dis[j]=dis[p]+1;
q.push(j);
}
}
}
int ans=dis[id(1,n)];
cout<<(ans==INF?-1:ans)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
172116 KB |
Output is correct |
2 |
Correct |
104 ms |
172200 KB |
Output is correct |
3 |
Correct |
98 ms |
172156 KB |
Output is correct |
4 |
Execution timed out |
2061 ms |
901840 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
172364 KB |
Output is correct |
2 |
Correct |
103 ms |
172364 KB |
Output is correct |
3 |
Correct |
103 ms |
172116 KB |
Output is correct |
4 |
Correct |
105 ms |
172368 KB |
Output is correct |
5 |
Correct |
102 ms |
172372 KB |
Output is correct |
6 |
Correct |
104 ms |
172372 KB |
Output is correct |
7 |
Correct |
102 ms |
172372 KB |
Output is correct |
8 |
Correct |
106 ms |
172368 KB |
Output is correct |
9 |
Correct |
101 ms |
172368 KB |
Output is correct |
10 |
Correct |
102 ms |
172136 KB |
Output is correct |
11 |
Correct |
140 ms |
194640 KB |
Output is correct |
12 |
Correct |
149 ms |
197352 KB |
Output is correct |
13 |
Correct |
145 ms |
198480 KB |
Output is correct |
14 |
Correct |
139 ms |
195152 KB |
Output is correct |
15 |
Correct |
144 ms |
198480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
172364 KB |
Output is correct |
2 |
Correct |
103 ms |
172364 KB |
Output is correct |
3 |
Correct |
103 ms |
172116 KB |
Output is correct |
4 |
Correct |
105 ms |
172368 KB |
Output is correct |
5 |
Correct |
102 ms |
172372 KB |
Output is correct |
6 |
Correct |
104 ms |
172372 KB |
Output is correct |
7 |
Correct |
102 ms |
172372 KB |
Output is correct |
8 |
Correct |
106 ms |
172368 KB |
Output is correct |
9 |
Correct |
101 ms |
172368 KB |
Output is correct |
10 |
Correct |
102 ms |
172136 KB |
Output is correct |
11 |
Correct |
140 ms |
194640 KB |
Output is correct |
12 |
Correct |
149 ms |
197352 KB |
Output is correct |
13 |
Correct |
145 ms |
198480 KB |
Output is correct |
14 |
Correct |
139 ms |
195152 KB |
Output is correct |
15 |
Correct |
144 ms |
198480 KB |
Output is correct |
16 |
Execution timed out |
2047 ms |
884008 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
172364 KB |
Output is correct |
2 |
Correct |
103 ms |
172364 KB |
Output is correct |
3 |
Correct |
103 ms |
172116 KB |
Output is correct |
4 |
Correct |
105 ms |
172368 KB |
Output is correct |
5 |
Correct |
102 ms |
172372 KB |
Output is correct |
6 |
Correct |
104 ms |
172372 KB |
Output is correct |
7 |
Correct |
102 ms |
172372 KB |
Output is correct |
8 |
Correct |
106 ms |
172368 KB |
Output is correct |
9 |
Correct |
101 ms |
172368 KB |
Output is correct |
10 |
Correct |
102 ms |
172136 KB |
Output is correct |
11 |
Correct |
140 ms |
194640 KB |
Output is correct |
12 |
Correct |
149 ms |
197352 KB |
Output is correct |
13 |
Correct |
145 ms |
198480 KB |
Output is correct |
14 |
Correct |
139 ms |
195152 KB |
Output is correct |
15 |
Correct |
144 ms |
198480 KB |
Output is correct |
16 |
Execution timed out |
2047 ms |
884008 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
172116 KB |
Output is correct |
2 |
Correct |
104 ms |
172200 KB |
Output is correct |
3 |
Correct |
98 ms |
172156 KB |
Output is correct |
4 |
Execution timed out |
2061 ms |
901840 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |