/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/
#include <bits/stdc++.h>
#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define int long long
#define mk make_pair
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e15 + 7;
vector < int > w[N];
priority_queue < pair < int, int > > q;
int n, m, p, b, x, s, cnt, to;
int d[N];
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
scanf("%lld%lld", &n, &m);
for( int i = 1; i <= m; i++ )
{
scanf("%lld%lld", &p, &b);
p++;
if( i == 1 )
s = p;
if( i == 2 )
x = p;
w[ p ].pb( b );
}
for ( int i = 1; i <= n; i ++ )
{
sort( w[i].begin(), w[i].end() );
w[i].erase( unique( w[i].begin(), w[i].end() ), w[i].end() );
}
for (int i = 1; i <= n; i ++)
d[i] = inf;
d[ s ] = 0;
q.push( mk( d[s], s ) );
while( !q.empty() )
{
int v = q.top().sc, cur = -q.top().fr;
q.pop();
if( cur > d[ v ] ) continue;
if (v == x)
{
printf("%lld", d[v]);
return 0;
}
for( auto l : w[v] )
{
for( int i = 1; i * l + v <= n; i++ )
{
to = v + l * i;
if( d[ v ] + i < d[ to ] )
{
d[ to ] = d[ v ] + i;
q.push( mk( -d[ to ], to ) );
}
}
for( int i = 1; i * l <= v; i++ )
{
to = v - l * i;
if( d[ v ] + i < d[ to ] )
{
d[ to ] = d[ v ] + i;
q.push( mk( -d[ to ], to ) );
}
}
}
}
if( d[ x ] == inf )
puts("-1");
else
printf("%lld", d[x]);
}
Compilation message
skyscraper.cpp:32:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:38:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:42:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &p, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
7 ms |
5132 KB |
Output is correct |
3 |
Correct |
5 ms |
5156 KB |
Output is correct |
4 |
Correct |
6 ms |
5156 KB |
Output is correct |
5 |
Correct |
6 ms |
5256 KB |
Output is correct |
6 |
Correct |
5 ms |
5256 KB |
Output is correct |
7 |
Correct |
7 ms |
5308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5308 KB |
Output is correct |
2 |
Correct |
7 ms |
5308 KB |
Output is correct |
3 |
Correct |
7 ms |
5308 KB |
Output is correct |
4 |
Correct |
5 ms |
5308 KB |
Output is correct |
5 |
Correct |
5 ms |
5308 KB |
Output is correct |
6 |
Correct |
5 ms |
5316 KB |
Output is correct |
7 |
Correct |
7 ms |
5316 KB |
Output is correct |
8 |
Correct |
7 ms |
5316 KB |
Output is correct |
9 |
Correct |
5 ms |
5316 KB |
Output is correct |
10 |
Correct |
6 ms |
5356 KB |
Output is correct |
11 |
Correct |
8 ms |
5376 KB |
Output is correct |
12 |
Correct |
6 ms |
5376 KB |
Output is correct |
13 |
Correct |
6 ms |
5376 KB |
Output is correct |
14 |
Correct |
6 ms |
5376 KB |
Output is correct |
15 |
Correct |
6 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5376 KB |
Output is correct |
2 |
Correct |
5 ms |
5376 KB |
Output is correct |
3 |
Correct |
5 ms |
5376 KB |
Output is correct |
4 |
Correct |
5 ms |
5376 KB |
Output is correct |
5 |
Correct |
7 ms |
5376 KB |
Output is correct |
6 |
Correct |
5 ms |
5376 KB |
Output is correct |
7 |
Correct |
5 ms |
5376 KB |
Output is correct |
8 |
Correct |
5 ms |
5376 KB |
Output is correct |
9 |
Correct |
6 ms |
5376 KB |
Output is correct |
10 |
Correct |
6 ms |
5376 KB |
Output is correct |
11 |
Correct |
6 ms |
5376 KB |
Output is correct |
12 |
Correct |
6 ms |
5376 KB |
Output is correct |
13 |
Correct |
7 ms |
5376 KB |
Output is correct |
14 |
Correct |
6 ms |
5376 KB |
Output is correct |
15 |
Correct |
6 ms |
5376 KB |
Output is correct |
16 |
Correct |
6 ms |
5376 KB |
Output is correct |
17 |
Correct |
6 ms |
5376 KB |
Output is correct |
18 |
Correct |
6 ms |
5376 KB |
Output is correct |
19 |
Correct |
5 ms |
5376 KB |
Output is correct |
20 |
Correct |
11 ms |
5376 KB |
Output is correct |
21 |
Correct |
6 ms |
5376 KB |
Output is correct |
22 |
Correct |
5 ms |
5376 KB |
Output is correct |
23 |
Correct |
6 ms |
5376 KB |
Output is correct |
24 |
Correct |
7 ms |
5376 KB |
Output is correct |
25 |
Correct |
6 ms |
5376 KB |
Output is correct |
26 |
Correct |
6 ms |
5376 KB |
Output is correct |
27 |
Correct |
6 ms |
5376 KB |
Output is correct |
28 |
Correct |
7 ms |
5376 KB |
Output is correct |
29 |
Correct |
7 ms |
5756 KB |
Output is correct |
30 |
Correct |
6 ms |
5756 KB |
Output is correct |
31 |
Correct |
8 ms |
5756 KB |
Output is correct |
32 |
Correct |
7 ms |
5756 KB |
Output is correct |
33 |
Correct |
9 ms |
5756 KB |
Output is correct |
34 |
Correct |
7 ms |
5756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5756 KB |
Output is correct |
2 |
Correct |
6 ms |
5756 KB |
Output is correct |
3 |
Correct |
6 ms |
5756 KB |
Output is correct |
4 |
Correct |
7 ms |
5756 KB |
Output is correct |
5 |
Correct |
6 ms |
5756 KB |
Output is correct |
6 |
Correct |
6 ms |
5756 KB |
Output is correct |
7 |
Correct |
5 ms |
5756 KB |
Output is correct |
8 |
Correct |
6 ms |
5756 KB |
Output is correct |
9 |
Correct |
6 ms |
5756 KB |
Output is correct |
10 |
Correct |
6 ms |
5756 KB |
Output is correct |
11 |
Correct |
7 ms |
5756 KB |
Output is correct |
12 |
Correct |
6 ms |
5756 KB |
Output is correct |
13 |
Correct |
7 ms |
5756 KB |
Output is correct |
14 |
Correct |
6 ms |
5756 KB |
Output is correct |
15 |
Correct |
6 ms |
5756 KB |
Output is correct |
16 |
Correct |
5 ms |
5756 KB |
Output is correct |
17 |
Correct |
7 ms |
5756 KB |
Output is correct |
18 |
Correct |
6 ms |
5756 KB |
Output is correct |
19 |
Correct |
5 ms |
5756 KB |
Output is correct |
20 |
Correct |
12 ms |
5756 KB |
Output is correct |
21 |
Correct |
6 ms |
5756 KB |
Output is correct |
22 |
Correct |
5 ms |
5756 KB |
Output is correct |
23 |
Correct |
6 ms |
5756 KB |
Output is correct |
24 |
Correct |
7 ms |
5756 KB |
Output is correct |
25 |
Correct |
6 ms |
5756 KB |
Output is correct |
26 |
Correct |
7 ms |
5756 KB |
Output is correct |
27 |
Correct |
6 ms |
5756 KB |
Output is correct |
28 |
Correct |
7 ms |
5756 KB |
Output is correct |
29 |
Correct |
7 ms |
5756 KB |
Output is correct |
30 |
Correct |
6 ms |
5756 KB |
Output is correct |
31 |
Correct |
7 ms |
5756 KB |
Output is correct |
32 |
Correct |
7 ms |
5756 KB |
Output is correct |
33 |
Correct |
9 ms |
5756 KB |
Output is correct |
34 |
Correct |
7 ms |
5756 KB |
Output is correct |
35 |
Correct |
15 ms |
5756 KB |
Output is correct |
36 |
Correct |
10 ms |
5756 KB |
Output is correct |
37 |
Correct |
13 ms |
5756 KB |
Output is correct |
38 |
Correct |
16 ms |
5900 KB |
Output is correct |
39 |
Correct |
18 ms |
5900 KB |
Output is correct |
40 |
Correct |
16 ms |
6012 KB |
Output is correct |
41 |
Correct |
16 ms |
6012 KB |
Output is correct |
42 |
Correct |
12 ms |
6012 KB |
Output is correct |
43 |
Correct |
12 ms |
6012 KB |
Output is correct |
44 |
Correct |
18 ms |
6012 KB |
Output is correct |
45 |
Correct |
16 ms |
6012 KB |
Output is correct |
46 |
Correct |
16 ms |
6140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6140 KB |
Output is correct |
2 |
Correct |
5 ms |
6140 KB |
Output is correct |
3 |
Correct |
5 ms |
6140 KB |
Output is correct |
4 |
Correct |
6 ms |
6140 KB |
Output is correct |
5 |
Correct |
5 ms |
6140 KB |
Output is correct |
6 |
Correct |
6 ms |
6140 KB |
Output is correct |
7 |
Correct |
5 ms |
6140 KB |
Output is correct |
8 |
Correct |
5 ms |
6140 KB |
Output is correct |
9 |
Correct |
5 ms |
6140 KB |
Output is correct |
10 |
Correct |
7 ms |
6140 KB |
Output is correct |
11 |
Correct |
7 ms |
6140 KB |
Output is correct |
12 |
Correct |
7 ms |
6140 KB |
Output is correct |
13 |
Correct |
6 ms |
6140 KB |
Output is correct |
14 |
Correct |
6 ms |
6140 KB |
Output is correct |
15 |
Correct |
6 ms |
6140 KB |
Output is correct |
16 |
Correct |
7 ms |
6140 KB |
Output is correct |
17 |
Correct |
6 ms |
6140 KB |
Output is correct |
18 |
Correct |
6 ms |
6140 KB |
Output is correct |
19 |
Correct |
6 ms |
6140 KB |
Output is correct |
20 |
Correct |
11 ms |
6140 KB |
Output is correct |
21 |
Correct |
7 ms |
6140 KB |
Output is correct |
22 |
Correct |
5 ms |
6140 KB |
Output is correct |
23 |
Correct |
6 ms |
6140 KB |
Output is correct |
24 |
Correct |
7 ms |
6140 KB |
Output is correct |
25 |
Correct |
6 ms |
6140 KB |
Output is correct |
26 |
Correct |
6 ms |
6140 KB |
Output is correct |
27 |
Correct |
6 ms |
6140 KB |
Output is correct |
28 |
Correct |
6 ms |
6140 KB |
Output is correct |
29 |
Correct |
7 ms |
6140 KB |
Output is correct |
30 |
Correct |
6 ms |
6140 KB |
Output is correct |
31 |
Correct |
7 ms |
6140 KB |
Output is correct |
32 |
Correct |
6 ms |
6140 KB |
Output is correct |
33 |
Correct |
9 ms |
6140 KB |
Output is correct |
34 |
Correct |
7 ms |
6140 KB |
Output is correct |
35 |
Correct |
14 ms |
6140 KB |
Output is correct |
36 |
Correct |
8 ms |
6140 KB |
Output is correct |
37 |
Correct |
16 ms |
6140 KB |
Output is correct |
38 |
Correct |
23 ms |
6140 KB |
Output is correct |
39 |
Correct |
15 ms |
6140 KB |
Output is correct |
40 |
Correct |
15 ms |
6140 KB |
Output is correct |
41 |
Correct |
16 ms |
6140 KB |
Output is correct |
42 |
Correct |
13 ms |
6140 KB |
Output is correct |
43 |
Correct |
18 ms |
6140 KB |
Output is correct |
44 |
Correct |
22 ms |
6140 KB |
Output is correct |
45 |
Correct |
16 ms |
6140 KB |
Output is correct |
46 |
Correct |
15 ms |
6140 KB |
Output is correct |
47 |
Correct |
22 ms |
7104 KB |
Output is correct |
48 |
Correct |
15 ms |
7104 KB |
Output is correct |
49 |
Correct |
22 ms |
7104 KB |
Output is correct |
50 |
Correct |
12 ms |
7104 KB |
Output is correct |
51 |
Correct |
43 ms |
8308 KB |
Output is correct |
52 |
Correct |
37 ms |
8308 KB |
Output is correct |
53 |
Correct |
28 ms |
8308 KB |
Output is correct |
54 |
Correct |
10 ms |
8308 KB |
Output is correct |
55 |
Correct |
11 ms |
8308 KB |
Output is correct |
56 |
Execution timed out |
1035 ms |
8308 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |