#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define endl '\n'
using namespace std;
const int N = 3e4+5;
int b[N], p[N];
ll d[N];
vector<pii> adj[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> b[i] >> p[i];
d[i] = -1;
}
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++)
if (i != j && abs(b[i]-b[j]) % p[i] == 0)
adj[i].pb({j, abs(b[i]-b[j]) / p[i]});
priority_queue<pll, vector<pll>, greater<pll>> q;
q.push({0, 1});
while (q.size()) {
ll v = q.top().S, w = q.top().F;
q.pop();
if (d[v] != -1)
continue;
d[v] = w;
for (pii x : adj[v])
if (d[x.F] == -1)
q.push({w+x.S, x.F});
}
cout << d[2] << endl;
}
# |
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 |
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 |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
39 ms |
5332 KB |
Output is correct |
12 |
Correct |
469 ms |
49492 KB |
Output is correct |
13 |
Correct |
502 ms |
49704 KB |
Output is correct |
14 |
Correct |
32 ms |
3532 KB |
Output is correct |
15 |
Correct |
32 ms |
3600 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 |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
40 ms |
5348 KB |
Output is correct |
12 |
Correct |
473 ms |
49468 KB |
Output is correct |
13 |
Correct |
509 ms |
49696 KB |
Output is correct |
14 |
Correct |
32 ms |
3532 KB |
Output is correct |
15 |
Correct |
31 ms |
3508 KB |
Output is correct |
16 |
Correct |
5 ms |
1236 KB |
Output is correct |
17 |
Correct |
21 ms |
2256 KB |
Output is correct |
18 |
Correct |
6 ms |
1108 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
516 ms |
49664 KB |
Output is correct |
21 |
Correct |
8 ms |
1108 KB |
Output is correct |
22 |
Correct |
3 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
19 ms |
1308 KB |
Output is correct |
25 |
Correct |
21 ms |
1180 KB |
Output is correct |
26 |
Correct |
403 ms |
46636 KB |
Output is correct |
27 |
Correct |
410 ms |
47564 KB |
Output is correct |
28 |
Correct |
21 ms |
1272 KB |
Output is correct |
29 |
Correct |
5 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
3 ms |
1108 KB |
Output is correct |
32 |
Correct |
3 ms |
1108 KB |
Output is correct |
33 |
Correct |
33 ms |
3588 KB |
Output is correct |
34 |
Correct |
31 ms |
3584 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 |
1012 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 |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
39 ms |
5296 KB |
Output is correct |
12 |
Correct |
468 ms |
49568 KB |
Output is correct |
13 |
Correct |
490 ms |
49736 KB |
Output is correct |
14 |
Correct |
31 ms |
3532 KB |
Output is correct |
15 |
Correct |
31 ms |
3528 KB |
Output is correct |
16 |
Correct |
4 ms |
1260 KB |
Output is correct |
17 |
Correct |
20 ms |
2228 KB |
Output is correct |
18 |
Correct |
6 ms |
980 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
492 ms |
49672 KB |
Output is correct |
21 |
Correct |
8 ms |
1108 KB |
Output is correct |
22 |
Correct |
3 ms |
980 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
19 ms |
1364 KB |
Output is correct |
25 |
Correct |
21 ms |
1320 KB |
Output is correct |
26 |
Correct |
391 ms |
46660 KB |
Output is correct |
27 |
Correct |
405 ms |
47544 KB |
Output is correct |
28 |
Correct |
21 ms |
1260 KB |
Output is correct |
29 |
Correct |
6 ms |
1420 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
3 ms |
1108 KB |
Output is correct |
32 |
Correct |
3 ms |
1108 KB |
Output is correct |
33 |
Correct |
32 ms |
3620 KB |
Output is correct |
34 |
Correct |
33 ms |
3596 KB |
Output is correct |
35 |
Execution timed out |
1080 ms |
12464 KB |
Time limit exceeded |
36 |
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 |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
40 ms |
5360 KB |
Output is correct |
12 |
Correct |
472 ms |
49500 KB |
Output is correct |
13 |
Correct |
490 ms |
49696 KB |
Output is correct |
14 |
Correct |
31 ms |
3532 KB |
Output is correct |
15 |
Correct |
31 ms |
3500 KB |
Output is correct |
16 |
Correct |
5 ms |
1336 KB |
Output is correct |
17 |
Correct |
21 ms |
2272 KB |
Output is correct |
18 |
Correct |
6 ms |
1068 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
494 ms |
49684 KB |
Output is correct |
21 |
Correct |
8 ms |
1160 KB |
Output is correct |
22 |
Correct |
3 ms |
1032 KB |
Output is correct |
23 |
Correct |
7 ms |
1108 KB |
Output is correct |
24 |
Correct |
19 ms |
1320 KB |
Output is correct |
25 |
Correct |
20 ms |
1228 KB |
Output is correct |
26 |
Correct |
382 ms |
46740 KB |
Output is correct |
27 |
Correct |
417 ms |
47560 KB |
Output is correct |
28 |
Correct |
20 ms |
1228 KB |
Output is correct |
29 |
Correct |
5 ms |
1452 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
3 ms |
1108 KB |
Output is correct |
32 |
Correct |
3 ms |
1028 KB |
Output is correct |
33 |
Correct |
31 ms |
3620 KB |
Output is correct |
34 |
Correct |
32 ms |
3568 KB |
Output is correct |
35 |
Execution timed out |
1079 ms |
12396 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |