#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
const int N = 30010,mod = 1e9+7;
int vstd[N],added[N];
pair<int,int>A[N];
vector<int> tile[N];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i = 0;i<m;i++)
{
cin>>A[i].F>>A[i].S;
tile[A[i].F].pb(i);
}
priority_queue<pair<int,int>>pq;
for(auto u:tile[A[0].F])
{
pq.push({0,u});
added[u] = 1;
}
while(!pq.empty())
{
int nd = pq.top().S;
int jumps = -pq.top().F;
int x = A[nd].F;
int p = A[nd].S;
pq.pop();
added[nd] = 1;
if(vstd[nd])continue;
vstd[nd] = 1;
if(nd==1)
{
cout<<jumps<<endl;
return 0;
}
int k = 1;
for(int i = x+p;i<n;i+=p)
{
for(auto u:tile[i])
{
if(added[u])continue;
pq.push({-(k+jumps),u});
}
k++;
}
k = 1;
for(int i = x-p;i>=0;i-=p)
{
for(auto u:tile[i])
{
if(added[u])continue;
pq.push({-(k+jumps),u});
}
k++;
}
}
cout<<-1<<endl;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
30 ms |
3280 KB |
Output is correct |
14 |
Correct |
5 ms |
1368 KB |
Output is correct |
15 |
Correct |
3 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
1364 KB |
Output is correct |
12 |
Correct |
2 ms |
1108 KB |
Output is correct |
13 |
Correct |
30 ms |
3268 KB |
Output is correct |
14 |
Correct |
4 ms |
1368 KB |
Output is correct |
15 |
Correct |
3 ms |
1368 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
308 ms |
9480 KB |
Output is correct |
21 |
Correct |
2 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
2 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
980 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
5 ms |
1368 KB |
Output is correct |
34 |
Correct |
4 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
1492 KB |
Output is correct |
12 |
Correct |
2 ms |
1108 KB |
Output is correct |
13 |
Correct |
28 ms |
3280 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
3 ms |
1368 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
311 ms |
9468 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
980 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
5 ms |
1432 KB |
Output is correct |
34 |
Correct |
5 ms |
1416 KB |
Output is correct |
35 |
Correct |
84 ms |
18192 KB |
Output is correct |
36 |
Correct |
2 ms |
1364 KB |
Output is correct |
37 |
Correct |
55 ms |
17988 KB |
Output is correct |
38 |
Correct |
80 ms |
18212 KB |
Output is correct |
39 |
Correct |
6 ms |
2004 KB |
Output is correct |
40 |
Correct |
18 ms |
5956 KB |
Output is correct |
41 |
Correct |
65 ms |
18248 KB |
Output is correct |
42 |
Correct |
6 ms |
1492 KB |
Output is correct |
43 |
Correct |
105 ms |
2592 KB |
Output is correct |
44 |
Runtime error |
504 ms |
262144 KB |
Execution killed with signal 9 |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
1364 KB |
Output is correct |
12 |
Correct |
2 ms |
1108 KB |
Output is correct |
13 |
Correct |
34 ms |
3280 KB |
Output is correct |
14 |
Correct |
4 ms |
1368 KB |
Output is correct |
15 |
Correct |
3 ms |
1368 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
315 ms |
9408 KB |
Output is correct |
21 |
Correct |
2 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
980 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
980 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
2 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
1072 KB |
Output is correct |
33 |
Correct |
5 ms |
1368 KB |
Output is correct |
34 |
Correct |
4 ms |
1368 KB |
Output is correct |
35 |
Correct |
94 ms |
18160 KB |
Output is correct |
36 |
Correct |
2 ms |
1364 KB |
Output is correct |
37 |
Correct |
65 ms |
18052 KB |
Output is correct |
38 |
Correct |
88 ms |
18212 KB |
Output is correct |
39 |
Correct |
7 ms |
2112 KB |
Output is correct |
40 |
Correct |
19 ms |
5956 KB |
Output is correct |
41 |
Correct |
64 ms |
18220 KB |
Output is correct |
42 |
Correct |
5 ms |
1492 KB |
Output is correct |
43 |
Correct |
95 ms |
2628 KB |
Output is correct |
44 |
Runtime error |
476 ms |
262144 KB |
Execution killed with signal 9 |
45 |
Halted |
0 ms |
0 KB |
- |