#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define MAXN 30005
int n, m, t[MAXN], s, e;
pair<int, int> d[MAXN];
vector<int> p[MAXN];
priority_queue<pair<int, int>> pq;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
FOR(i, 0, m - 1) t[i] = -1;
FOR(i, 0, m - 1){
cin >> d[i].first >> d[i].second;
if(i == 0) {
s = d[i].first;
t[0] = 0;
pq.push({-t[0], 0});
}
if(i == 1) e = d[i].first;
}
while(pq.size()){
int v = pq.top().first;
int pqi = pq.top().second; pq.pop();
if(t[pqi] != -v) continue;
// cout << pqi << " " << -v << endl;
FOR(i, 0, m - 1) if(i != pqi){
if(abs(d[pqi].first - d[i].first) % d[pqi].second == 0 && (t[i] == -1 || t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second < t[i])){
t[i] = t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second;
pq.push({-t[i], i});
// cout << " => " << i << " " << t[i] << " " << d[pqi].second << endl;
}
}
}
cout << t[1] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
0 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
11 ms |
1272 KB |
Output is correct |
12 |
Correct |
9 ms |
1116 KB |
Output is correct |
13 |
Correct |
9 ms |
1116 KB |
Output is correct |
14 |
Correct |
11 ms |
1312 KB |
Output is correct |
15 |
Correct |
10 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1168 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1168 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1168 KB |
Output is correct |
11 |
Correct |
11 ms |
1116 KB |
Output is correct |
12 |
Correct |
9 ms |
1112 KB |
Output is correct |
13 |
Correct |
9 ms |
1240 KB |
Output is correct |
14 |
Correct |
10 ms |
1116 KB |
Output is correct |
15 |
Correct |
11 ms |
1116 KB |
Output is correct |
16 |
Correct |
0 ms |
1168 KB |
Output is correct |
17 |
Correct |
8 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
9 ms |
1240 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
8 ms |
1244 KB |
Output is correct |
25 |
Correct |
9 ms |
1268 KB |
Output is correct |
26 |
Correct |
11 ms |
1116 KB |
Output is correct |
27 |
Correct |
9 ms |
1196 KB |
Output is correct |
28 |
Correct |
9 ms |
1116 KB |
Output is correct |
29 |
Correct |
3 ms |
1112 KB |
Output is correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
1196 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
10 ms |
1112 KB |
Output is correct |
34 |
Correct |
11 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
11 ms |
1184 KB |
Output is correct |
12 |
Correct |
9 ms |
1112 KB |
Output is correct |
13 |
Correct |
9 ms |
1116 KB |
Output is correct |
14 |
Correct |
11 ms |
1116 KB |
Output is correct |
15 |
Correct |
10 ms |
1316 KB |
Output is correct |
16 |
Correct |
1 ms |
1112 KB |
Output is correct |
17 |
Correct |
8 ms |
1268 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
10 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
8 ms |
1228 KB |
Output is correct |
25 |
Correct |
9 ms |
1232 KB |
Output is correct |
26 |
Correct |
9 ms |
1244 KB |
Output is correct |
27 |
Correct |
9 ms |
1248 KB |
Output is correct |
28 |
Correct |
9 ms |
1116 KB |
Output is correct |
29 |
Correct |
2 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
11 ms |
1312 KB |
Output is correct |
34 |
Correct |
10 ms |
1116 KB |
Output is correct |
35 |
Execution timed out |
1053 ms |
2268 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
1116 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
12 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1116 KB |
Output is correct |
13 |
Correct |
9 ms |
1240 KB |
Output is correct |
14 |
Correct |
11 ms |
1112 KB |
Output is correct |
15 |
Correct |
11 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
8 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
9 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
8 ms |
1116 KB |
Output is correct |
25 |
Correct |
9 ms |
1116 KB |
Output is correct |
26 |
Correct |
9 ms |
1232 KB |
Output is correct |
27 |
Correct |
9 ms |
1116 KB |
Output is correct |
28 |
Correct |
9 ms |
1112 KB |
Output is correct |
29 |
Correct |
2 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1172 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
11 ms |
1116 KB |
Output is correct |
34 |
Correct |
10 ms |
1312 KB |
Output is correct |
35 |
Execution timed out |
1097 ms |
2080 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |