#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
ll ab (ll x ) { return (x>0?x:-x); }
const int N = 300005 ;
const ll oo = 1e18 ;
ll dist [N] ;
set<int> dogs;
// int par[N];
ll n , m ;
ll B[N] , P[N] ;
ll dijkstra(){
priority_queue< pll, vector <pll> , greater<pll> > pq;
pq.push( mp(0,0) ) ;
for(int i = 1 ; i <= m ; i++ )dist[i] = oo ;
dist[0] = 0LL ;
// vector<int> choosen ;
while ( !pq.empty() ){
int u = pq.top().se ;
ll d = pq.top().fi ;
pq.pop() ;
if( dogs.find ( u ) != dogs.end() )
dogs.erase( dogs.find (u) ) ;
if( u == 1 )return dist[1] ;
if( dist[u] < d )continue ;
for(int v : dogs ){
d = dist[u] + ab(B[u]-B[v]) / P[u] ;
if(ab(B[u]-B[v])%P[u] == 0LL && dist[v] > d ){
// cout << u << " " << v << endl;
dist[v] = d;
pq.push( {d ,v} );
}
}
} return -1 ;
}
void input(){
// fastio ;
// ifstream cin("in.in") ;
cin >> n >> m ;
for(int i = 0 ; i < m ; i++ ){
cin >> B[i] >> P[i] ;
if(i)dogs.insert(i) ;
}
}
int main(){
input() ;
cout << dijkstra( ) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
504 KB |
Output is correct |
14 |
Correct |
44 ms |
732 KB |
Output is correct |
15 |
Correct |
41 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
252 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
504 KB |
Output is correct |
14 |
Correct |
43 ms |
736 KB |
Output is correct |
15 |
Correct |
43 ms |
632 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
30 ms |
632 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
42 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
11 ms |
376 KB |
Output is correct |
24 |
Correct |
37 ms |
504 KB |
Output is correct |
25 |
Correct |
15 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
9 ms |
508 KB |
Output is correct |
28 |
Correct |
41 ms |
504 KB |
Output is correct |
29 |
Correct |
8 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
248 KB |
Output is correct |
33 |
Correct |
42 ms |
636 KB |
Output is correct |
34 |
Correct |
42 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
508 KB |
Output is correct |
14 |
Correct |
42 ms |
632 KB |
Output is correct |
15 |
Correct |
41 ms |
760 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
28 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
43 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
11 ms |
376 KB |
Output is correct |
24 |
Correct |
37 ms |
504 KB |
Output is correct |
25 |
Correct |
15 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
8 ms |
504 KB |
Output is correct |
28 |
Correct |
41 ms |
516 KB |
Output is correct |
29 |
Correct |
8 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
41 ms |
632 KB |
Output is correct |
34 |
Correct |
42 ms |
632 KB |
Output is correct |
35 |
Execution timed out |
1075 ms |
3312 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
632 KB |
Output is correct |
14 |
Correct |
42 ms |
760 KB |
Output is correct |
15 |
Correct |
41 ms |
728 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
29 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
43 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
11 ms |
376 KB |
Output is correct |
24 |
Correct |
37 ms |
504 KB |
Output is correct |
25 |
Correct |
15 ms |
376 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
8 ms |
504 KB |
Output is correct |
28 |
Correct |
41 ms |
504 KB |
Output is correct |
29 |
Correct |
8 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
33 |
Correct |
42 ms |
760 KB |
Output is correct |
34 |
Correct |
42 ms |
760 KB |
Output is correct |
35 |
Execution timed out |
1076 ms |
3432 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |