/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <string>
#include <memory.h>
#include <set>
#include <assert.h>
#define sz(s) s.size()
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 2e3 + 5;
const int inf = 1e9 + 7;
int n, m, p, b, x, s, cnt, dp[ 2000 ][ 2000 ];
vector < int > w[N];
main()
{
scanf("%d%d", &n, &m);
for( int i = 1; i <= m; i++ )
{
scanf("%d%d", &p, &b);
p++;
if( i == 1 )
s = p;
if( i == 2 )
x = p;
w[ p ].pb( b );
}
vector < int > d( n + 1, inf ), p( n + 1 );
d[ s ] = 0;
set < pair < int, int > > q;
q.insert( mk( d[s], s ) );
while( !q.empty() )
{
int v = q.begin() -> sc;
q.erase( q.begin() );
if (v == x) {
printf("%d", d[v]);
return 0;
}
for( int l : w[v] )
{
int to = v;
cnt = 0;
while( to <= n )
{
cnt++;
to = v + l * cnt;
if( to > n ) break;
if( d[ v ] + cnt < d[ to ] )
{
q.erase( mk( d[ to ], to ) );
d[ to ] = d[ v ] + cnt;
q.insert( mk( d[ to ], to ) );
}
}
to = v;
cnt = 0;
while( to )
{
cnt++;
to = v - l * cnt;
if( to <= 0 ) break;
if( d[ v ] + cnt < d[ to ] )
{
q.erase( mk( d[ to ], to ) );
d[ to ] = d[ v ] + cnt;
q.insert( mk( d[ to ], to ) );
}
}
}
}
if( d[ x ] == inf )
d[ x ] = -1;
printf("%d", d[x]);
}
Compilation message
skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:45:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &p, &b);
~~~~~^~~~~~~~~~~~~~~~
# |
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 |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
532 KB |
Output is correct |
7 |
Correct |
2 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
612 KB |
Output is correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
612 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
616 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
3 ms |
616 KB |
Output is correct |
14 |
Correct |
3 ms |
620 KB |
Output is correct |
15 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
640 KB |
Output is correct |
20 |
Correct |
15 ms |
764 KB |
Output is correct |
21 |
Correct |
3 ms |
764 KB |
Output is correct |
22 |
Correct |
2 ms |
764 KB |
Output is correct |
23 |
Correct |
3 ms |
764 KB |
Output is correct |
24 |
Correct |
5 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
4 ms |
764 KB |
Output is correct |
27 |
Correct |
3 ms |
764 KB |
Output is correct |
28 |
Correct |
3 ms |
764 KB |
Output is correct |
29 |
Correct |
6 ms |
764 KB |
Output is correct |
30 |
Correct |
3 ms |
764 KB |
Output is correct |
31 |
Correct |
5 ms |
764 KB |
Output is correct |
32 |
Correct |
4 ms |
764 KB |
Output is correct |
33 |
Correct |
6 ms |
764 KB |
Output is correct |
34 |
Correct |
7 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
764 KB |
Output is correct |
6 |
Correct |
2 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
764 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
764 KB |
Output is correct |
16 |
Correct |
3 ms |
764 KB |
Output is correct |
17 |
Correct |
3 ms |
764 KB |
Output is correct |
18 |
Correct |
2 ms |
764 KB |
Output is correct |
19 |
Correct |
3 ms |
764 KB |
Output is correct |
20 |
Correct |
19 ms |
764 KB |
Output is correct |
21 |
Correct |
3 ms |
764 KB |
Output is correct |
22 |
Correct |
3 ms |
764 KB |
Output is correct |
23 |
Correct |
3 ms |
764 KB |
Output is correct |
24 |
Correct |
4 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
4 ms |
764 KB |
Output is correct |
27 |
Correct |
3 ms |
764 KB |
Output is correct |
28 |
Correct |
4 ms |
764 KB |
Output is correct |
29 |
Correct |
8 ms |
892 KB |
Output is correct |
30 |
Correct |
5 ms |
892 KB |
Output is correct |
31 |
Correct |
6 ms |
892 KB |
Output is correct |
32 |
Correct |
5 ms |
892 KB |
Output is correct |
33 |
Correct |
7 ms |
892 KB |
Output is correct |
34 |
Correct |
8 ms |
892 KB |
Output is correct |
35 |
Correct |
14 ms |
896 KB |
Output is correct |
36 |
Correct |
6 ms |
896 KB |
Output is correct |
37 |
Correct |
17 ms |
904 KB |
Output is correct |
38 |
Correct |
17 ms |
904 KB |
Output is correct |
39 |
Correct |
15 ms |
904 KB |
Output is correct |
40 |
Correct |
18 ms |
904 KB |
Output is correct |
41 |
Correct |
14 ms |
904 KB |
Output is correct |
42 |
Correct |
9 ms |
904 KB |
Output is correct |
43 |
Correct |
15 ms |
904 KB |
Output is correct |
44 |
Correct |
199 ms |
904 KB |
Output is correct |
45 |
Correct |
15 ms |
904 KB |
Output is correct |
46 |
Correct |
15 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
956 KB |
Output is correct |
2 |
Correct |
2 ms |
956 KB |
Output is correct |
3 |
Correct |
2 ms |
956 KB |
Output is correct |
4 |
Correct |
3 ms |
956 KB |
Output is correct |
5 |
Correct |
2 ms |
956 KB |
Output is correct |
6 |
Correct |
2 ms |
956 KB |
Output is correct |
7 |
Correct |
2 ms |
956 KB |
Output is correct |
8 |
Correct |
3 ms |
956 KB |
Output is correct |
9 |
Correct |
2 ms |
956 KB |
Output is correct |
10 |
Correct |
2 ms |
956 KB |
Output is correct |
11 |
Correct |
2 ms |
956 KB |
Output is correct |
12 |
Correct |
2 ms |
956 KB |
Output is correct |
13 |
Correct |
4 ms |
956 KB |
Output is correct |
14 |
Correct |
3 ms |
956 KB |
Output is correct |
15 |
Correct |
3 ms |
956 KB |
Output is correct |
16 |
Correct |
3 ms |
956 KB |
Output is correct |
17 |
Correct |
3 ms |
956 KB |
Output is correct |
18 |
Correct |
3 ms |
956 KB |
Output is correct |
19 |
Correct |
2 ms |
956 KB |
Output is correct |
20 |
Correct |
14 ms |
956 KB |
Output is correct |
21 |
Correct |
2 ms |
956 KB |
Output is correct |
22 |
Correct |
3 ms |
956 KB |
Output is correct |
23 |
Correct |
3 ms |
956 KB |
Output is correct |
24 |
Correct |
5 ms |
956 KB |
Output is correct |
25 |
Correct |
3 ms |
956 KB |
Output is correct |
26 |
Correct |
3 ms |
956 KB |
Output is correct |
27 |
Correct |
3 ms |
956 KB |
Output is correct |
28 |
Correct |
3 ms |
956 KB |
Output is correct |
29 |
Correct |
5 ms |
956 KB |
Output is correct |
30 |
Correct |
5 ms |
956 KB |
Output is correct |
31 |
Correct |
6 ms |
956 KB |
Output is correct |
32 |
Correct |
5 ms |
956 KB |
Output is correct |
33 |
Correct |
7 ms |
956 KB |
Output is correct |
34 |
Correct |
6 ms |
956 KB |
Output is correct |
35 |
Correct |
13 ms |
956 KB |
Output is correct |
36 |
Correct |
6 ms |
956 KB |
Output is correct |
37 |
Correct |
17 ms |
956 KB |
Output is correct |
38 |
Correct |
18 ms |
956 KB |
Output is correct |
39 |
Correct |
11 ms |
956 KB |
Output is correct |
40 |
Correct |
17 ms |
956 KB |
Output is correct |
41 |
Correct |
14 ms |
956 KB |
Output is correct |
42 |
Correct |
8 ms |
956 KB |
Output is correct |
43 |
Correct |
7 ms |
956 KB |
Output is correct |
44 |
Correct |
191 ms |
956 KB |
Output is correct |
45 |
Correct |
20 ms |
956 KB |
Output is correct |
46 |
Correct |
14 ms |
956 KB |
Output is correct |
47 |
Correct |
51 ms |
1916 KB |
Output is correct |
48 |
Correct |
10 ms |
1916 KB |
Output is correct |
49 |
Correct |
16 ms |
1916 KB |
Output is correct |
50 |
Correct |
8 ms |
1916 KB |
Output is correct |
51 |
Correct |
81 ms |
3452 KB |
Output is correct |
52 |
Correct |
80 ms |
3452 KB |
Output is correct |
53 |
Correct |
29 ms |
3452 KB |
Output is correct |
54 |
Correct |
8 ms |
3452 KB |
Output is correct |
55 |
Correct |
8 ms |
3452 KB |
Output is correct |
56 |
Execution timed out |
1080 ms |
3836 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |