#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
int main(){
cin.sync_with_stdio(false);
ll n,m;
cin>>n>>m;
vi b(m);
vi p(m);
rep(i,0,m) cin>>b[i]>>p[i];
set<tuple<ll,ll> > q; //(jumps,doge);
q.emplace(0,0);
vector<bool> seen(m);
while(q.size()){
ll doge,jumps;
tie(jumps,doge) = *q.begin();
q.erase(q.begin());
if(seen[doge]) continue;
seen[doge] = true;
if(doge==1){
cout<<jumps<<endl;
return 0;
}
rep(i,0,m){
if((b[i]-b[doge])%p[doge]==0&&!seen[i])
q.emplace(jumps+abs(b[i]-b[doge])/p[doge],i);
}
}
cout<<-1<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
4 ms |
620 KB |
Output is correct |
12 |
Correct |
5 ms |
748 KB |
Output is correct |
13 |
Correct |
347 ms |
780 KB |
Output is correct |
14 |
Correct |
84 ms |
1260 KB |
Output is correct |
15 |
Correct |
75 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1260 KB |
Output is correct |
2 |
Correct |
3 ms |
1260 KB |
Output is correct |
3 |
Correct |
2 ms |
1260 KB |
Output is correct |
4 |
Correct |
3 ms |
1260 KB |
Output is correct |
5 |
Correct |
3 ms |
1260 KB |
Output is correct |
6 |
Correct |
3 ms |
1260 KB |
Output is correct |
7 |
Correct |
4 ms |
1260 KB |
Output is correct |
8 |
Correct |
3 ms |
1260 KB |
Output is correct |
9 |
Correct |
3 ms |
1260 KB |
Output is correct |
10 |
Correct |
4 ms |
1260 KB |
Output is correct |
11 |
Correct |
5 ms |
1260 KB |
Output is correct |
12 |
Correct |
4 ms |
1260 KB |
Output is correct |
13 |
Correct |
326 ms |
1260 KB |
Output is correct |
14 |
Correct |
94 ms |
1260 KB |
Output is correct |
15 |
Correct |
85 ms |
1284 KB |
Output is correct |
16 |
Correct |
2 ms |
1284 KB |
Output is correct |
17 |
Correct |
45 ms |
1612 KB |
Output is correct |
18 |
Correct |
2 ms |
1612 KB |
Output is correct |
19 |
Correct |
3 ms |
1612 KB |
Output is correct |
20 |
Correct |
443 ms |
1612 KB |
Output is correct |
21 |
Correct |
4 ms |
1612 KB |
Output is correct |
22 |
Correct |
3 ms |
1612 KB |
Output is correct |
23 |
Correct |
19 ms |
1612 KB |
Output is correct |
24 |
Correct |
65 ms |
1612 KB |
Output is correct |
25 |
Correct |
15 ms |
1612 KB |
Output is correct |
26 |
Correct |
4 ms |
1612 KB |
Output is correct |
27 |
Correct |
7 ms |
1612 KB |
Output is correct |
28 |
Correct |
72 ms |
1612 KB |
Output is correct |
29 |
Correct |
14 ms |
1612 KB |
Output is correct |
30 |
Correct |
8 ms |
1612 KB |
Output is correct |
31 |
Correct |
11 ms |
1612 KB |
Output is correct |
32 |
Correct |
8 ms |
1612 KB |
Output is correct |
33 |
Correct |
85 ms |
1612 KB |
Output is correct |
34 |
Correct |
84 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1612 KB |
Output is correct |
2 |
Correct |
2 ms |
1612 KB |
Output is correct |
3 |
Correct |
3 ms |
1612 KB |
Output is correct |
4 |
Correct |
2 ms |
1612 KB |
Output is correct |
5 |
Correct |
2 ms |
1612 KB |
Output is correct |
6 |
Correct |
2 ms |
1612 KB |
Output is correct |
7 |
Correct |
3 ms |
1612 KB |
Output is correct |
8 |
Correct |
3 ms |
1612 KB |
Output is correct |
9 |
Correct |
2 ms |
1612 KB |
Output is correct |
10 |
Correct |
5 ms |
1612 KB |
Output is correct |
11 |
Correct |
3 ms |
1612 KB |
Output is correct |
12 |
Correct |
3 ms |
1612 KB |
Output is correct |
13 |
Correct |
381 ms |
1612 KB |
Output is correct |
14 |
Correct |
86 ms |
1612 KB |
Output is correct |
15 |
Correct |
112 ms |
1612 KB |
Output is correct |
16 |
Correct |
3 ms |
1612 KB |
Output is correct |
17 |
Correct |
50 ms |
1624 KB |
Output is correct |
18 |
Correct |
4 ms |
1624 KB |
Output is correct |
19 |
Correct |
3 ms |
1624 KB |
Output is correct |
20 |
Correct |
465 ms |
1624 KB |
Output is correct |
21 |
Correct |
3 ms |
1624 KB |
Output is correct |
22 |
Correct |
3 ms |
1624 KB |
Output is correct |
23 |
Correct |
17 ms |
1624 KB |
Output is correct |
24 |
Correct |
57 ms |
1624 KB |
Output is correct |
25 |
Correct |
14 ms |
1624 KB |
Output is correct |
26 |
Correct |
4 ms |
1624 KB |
Output is correct |
27 |
Correct |
11 ms |
1624 KB |
Output is correct |
28 |
Correct |
91 ms |
1624 KB |
Output is correct |
29 |
Correct |
17 ms |
1624 KB |
Output is correct |
30 |
Correct |
3 ms |
1624 KB |
Output is correct |
31 |
Correct |
11 ms |
1624 KB |
Output is correct |
32 |
Correct |
6 ms |
1624 KB |
Output is correct |
33 |
Correct |
100 ms |
1624 KB |
Output is correct |
34 |
Correct |
103 ms |
1624 KB |
Output is correct |
35 |
Execution timed out |
1041 ms |
10212 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10212 KB |
Output is correct |
2 |
Correct |
3 ms |
10212 KB |
Output is correct |
3 |
Correct |
3 ms |
10212 KB |
Output is correct |
4 |
Correct |
4 ms |
10212 KB |
Output is correct |
5 |
Correct |
3 ms |
10212 KB |
Output is correct |
6 |
Correct |
3 ms |
10212 KB |
Output is correct |
7 |
Correct |
3 ms |
10212 KB |
Output is correct |
8 |
Correct |
2 ms |
10212 KB |
Output is correct |
9 |
Correct |
3 ms |
10212 KB |
Output is correct |
10 |
Correct |
4 ms |
10212 KB |
Output is correct |
11 |
Correct |
4 ms |
10212 KB |
Output is correct |
12 |
Correct |
3 ms |
10212 KB |
Output is correct |
13 |
Correct |
395 ms |
10212 KB |
Output is correct |
14 |
Correct |
108 ms |
10212 KB |
Output is correct |
15 |
Correct |
99 ms |
10212 KB |
Output is correct |
16 |
Correct |
3 ms |
10212 KB |
Output is correct |
17 |
Correct |
40 ms |
10212 KB |
Output is correct |
18 |
Correct |
3 ms |
10212 KB |
Output is correct |
19 |
Correct |
2 ms |
10212 KB |
Output is correct |
20 |
Correct |
462 ms |
10212 KB |
Output is correct |
21 |
Correct |
2 ms |
10212 KB |
Output is correct |
22 |
Correct |
4 ms |
10212 KB |
Output is correct |
23 |
Correct |
20 ms |
10212 KB |
Output is correct |
24 |
Correct |
56 ms |
10212 KB |
Output is correct |
25 |
Correct |
13 ms |
10212 KB |
Output is correct |
26 |
Correct |
4 ms |
10212 KB |
Output is correct |
27 |
Correct |
7 ms |
10212 KB |
Output is correct |
28 |
Correct |
72 ms |
10212 KB |
Output is correct |
29 |
Correct |
13 ms |
10212 KB |
Output is correct |
30 |
Correct |
4 ms |
10212 KB |
Output is correct |
31 |
Correct |
9 ms |
10212 KB |
Output is correct |
32 |
Correct |
7 ms |
10212 KB |
Output is correct |
33 |
Correct |
84 ms |
10212 KB |
Output is correct |
34 |
Correct |
97 ms |
10212 KB |
Output is correct |
35 |
Execution timed out |
1052 ms |
10244 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |