#include <bits/stdc++.h>
using namespace std;
int dist[2505][2505], ans[200005];
vector<int> adj[200005];
queue<int> q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
for (int i=1; i<=n; i++)
{
int l, r;
cin >> l >> r;
for (int j=l; j<=r; j++)
adj[i].push_back(j);
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
dist[i][j]=1e8;
dist[i][i]=0;
q.push(i);
while (!q.empty())
{
int u=q.front();
q.pop();
for (int v:adj[u])
{
if (dist[i][u]+1<dist[i][v])
{
dist[i][v]=dist[i][u]+1;
q.push(v);
}
}
}
}
for (int i=1; i<=n; i++)
{
ans[i]=min(dist[i][1]+dist[1][n], dist[i][n]+dist[n][1]);
for (int j=2; j<n; j++)
ans[i]=min(ans[i], dist[i][j]+dist[j][1]+dist[j][n]-1);
}
cin >> m;
for (int i=1; i<=m; i++)
{
int x;
cin >> x;
if (ans[x]<5e7)
cout << ans[x] << '\n';
else
cout << -1 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5024 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Runtime error |
965 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5028 KB |
Output is correct |
9 |
Correct |
4 ms |
5032 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
11 ms |
6620 KB |
Output is correct |
12 |
Correct |
5 ms |
6556 KB |
Output is correct |
13 |
Correct |
29 ms |
6844 KB |
Output is correct |
14 |
Correct |
17 ms |
6740 KB |
Output is correct |
15 |
Correct |
8 ms |
6564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5028 KB |
Output is correct |
9 |
Correct |
4 ms |
5032 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
11 ms |
6620 KB |
Output is correct |
12 |
Correct |
5 ms |
6556 KB |
Output is correct |
13 |
Correct |
29 ms |
6844 KB |
Output is correct |
14 |
Correct |
17 ms |
6740 KB |
Output is correct |
15 |
Correct |
8 ms |
6564 KB |
Output is correct |
16 |
Execution timed out |
2064 ms |
26168 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5024 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5028 KB |
Output is correct |
9 |
Correct |
4 ms |
5032 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
11 ms |
6620 KB |
Output is correct |
12 |
Correct |
5 ms |
6556 KB |
Output is correct |
13 |
Correct |
29 ms |
6844 KB |
Output is correct |
14 |
Correct |
17 ms |
6740 KB |
Output is correct |
15 |
Correct |
8 ms |
6564 KB |
Output is correct |
16 |
Execution timed out |
2064 ms |
26168 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5024 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Runtime error |
965 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |