#include <bits/stdc++.h>
#define Task "test"
#define pb emplace_back
#define mp make_pair
using namespace std;
const int N = 30001;
const int Irene = int(1e9) + 7;
typedef pair<int, int> pii;
int n, m, u, dis, st, en, d[N];
set<int> jump[N];
vector<pii> a[N];
priority_queue<pii, vector<pii>, greater<pii>> pq;
void Enter()
{
cin >> n >> m;
for(int i = 0; i < m; ++i) {
cin >> u >> dis;
if(!i) st = u;
else if(i == 1) en = u;
jump[u].insert(dis);
}
for(int i = 0; i < n; ++i) {
for(int len: jump[i]) {
int irene = i, step = 0;
while(++step, (irene -= len) >= 0) {
a[i].pb(irene, step);
if(jump[irene].find(len) != jump[irene].end()) break;
}
irene = i, step = 0;
while(++step, (irene += len) < n) {
a[i].pb(irene, step);
if(jump[irene].find(len) != jump[irene].end()) break;
}
}
}
}
void Solve()
{
fill(d, d + n, Irene);
d[st] = 0; pq.push(mp(0, st));
int u, dis;
while(pq.size()) {
pii top = pq.top(); pq.pop();
dis = top.first, u = top.second;
if(dis != d[u]) continue;
for(pii irene: a[u]) {
int Dis = irene.second + d[u];
if(Dis < d[irene.first]) d[irene.first] = Dis, pq.push(mp(Dis, irene.first));
}
}
if(d[en] == Irene) cout << -1;
else cout << d[en];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
Enter(), Solve();
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(Task".inp", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(Task".out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Correct |
4 ms |
2424 KB |
Output is correct |
7 |
Correct |
4 ms |
2428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2420 KB |
Output is correct |
6 |
Correct |
5 ms |
2424 KB |
Output is correct |
7 |
Correct |
4 ms |
2424 KB |
Output is correct |
8 |
Correct |
4 ms |
2424 KB |
Output is correct |
9 |
Correct |
4 ms |
2424 KB |
Output is correct |
10 |
Correct |
4 ms |
2552 KB |
Output is correct |
11 |
Correct |
5 ms |
2552 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
4 ms |
2424 KB |
Output is correct |
14 |
Correct |
5 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Correct |
4 ms |
2424 KB |
Output is correct |
7 |
Correct |
4 ms |
2424 KB |
Output is correct |
8 |
Correct |
4 ms |
2424 KB |
Output is correct |
9 |
Correct |
4 ms |
2424 KB |
Output is correct |
10 |
Correct |
4 ms |
2536 KB |
Output is correct |
11 |
Correct |
5 ms |
2552 KB |
Output is correct |
12 |
Correct |
4 ms |
2424 KB |
Output is correct |
13 |
Correct |
4 ms |
2424 KB |
Output is correct |
14 |
Correct |
5 ms |
2556 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
6 ms |
2552 KB |
Output is correct |
17 |
Correct |
6 ms |
2808 KB |
Output is correct |
18 |
Correct |
5 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
2552 KB |
Output is correct |
20 |
Correct |
6 ms |
2552 KB |
Output is correct |
21 |
Correct |
5 ms |
2552 KB |
Output is correct |
22 |
Correct |
4 ms |
2552 KB |
Output is correct |
23 |
Correct |
6 ms |
2680 KB |
Output is correct |
24 |
Correct |
6 ms |
2680 KB |
Output is correct |
25 |
Correct |
6 ms |
2760 KB |
Output is correct |
26 |
Correct |
5 ms |
2680 KB |
Output is correct |
27 |
Correct |
5 ms |
2552 KB |
Output is correct |
28 |
Correct |
5 ms |
2808 KB |
Output is correct |
29 |
Correct |
8 ms |
3384 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
6 ms |
2936 KB |
Output is correct |
32 |
Correct |
5 ms |
2808 KB |
Output is correct |
33 |
Correct |
10 ms |
4164 KB |
Output is correct |
34 |
Correct |
10 ms |
3976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Correct |
5 ms |
2400 KB |
Output is correct |
7 |
Correct |
4 ms |
2424 KB |
Output is correct |
8 |
Correct |
4 ms |
2424 KB |
Output is correct |
9 |
Correct |
4 ms |
2424 KB |
Output is correct |
10 |
Correct |
4 ms |
2552 KB |
Output is correct |
11 |
Correct |
5 ms |
2552 KB |
Output is correct |
12 |
Correct |
4 ms |
2424 KB |
Output is correct |
13 |
Correct |
4 ms |
2552 KB |
Output is correct |
14 |
Correct |
5 ms |
2552 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
6 ms |
2552 KB |
Output is correct |
17 |
Correct |
6 ms |
2684 KB |
Output is correct |
18 |
Correct |
5 ms |
2552 KB |
Output is correct |
19 |
Correct |
4 ms |
2552 KB |
Output is correct |
20 |
Correct |
5 ms |
2552 KB |
Output is correct |
21 |
Correct |
4 ms |
2552 KB |
Output is correct |
22 |
Correct |
4 ms |
2552 KB |
Output is correct |
23 |
Correct |
5 ms |
2552 KB |
Output is correct |
24 |
Correct |
6 ms |
2680 KB |
Output is correct |
25 |
Correct |
6 ms |
2680 KB |
Output is correct |
26 |
Correct |
5 ms |
2552 KB |
Output is correct |
27 |
Correct |
5 ms |
2552 KB |
Output is correct |
28 |
Correct |
6 ms |
2852 KB |
Output is correct |
29 |
Correct |
7 ms |
3320 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
5 ms |
2936 KB |
Output is correct |
32 |
Correct |
5 ms |
2760 KB |
Output is correct |
33 |
Correct |
10 ms |
4084 KB |
Output is correct |
34 |
Correct |
10 ms |
4084 KB |
Output is correct |
35 |
Correct |
25 ms |
4984 KB |
Output is correct |
36 |
Correct |
7 ms |
2940 KB |
Output is correct |
37 |
Correct |
28 ms |
5624 KB |
Output is correct |
38 |
Correct |
37 ms |
6032 KB |
Output is correct |
39 |
Correct |
33 ms |
6008 KB |
Output is correct |
40 |
Correct |
32 ms |
5880 KB |
Output is correct |
41 |
Correct |
33 ms |
5880 KB |
Output is correct |
42 |
Correct |
11 ms |
2808 KB |
Output is correct |
43 |
Correct |
9 ms |
2808 KB |
Output is correct |
44 |
Correct |
9 ms |
2780 KB |
Output is correct |
45 |
Correct |
35 ms |
8568 KB |
Output is correct |
46 |
Correct |
34 ms |
8584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
4 ms |
2424 KB |
Output is correct |
6 |
Correct |
4 ms |
2424 KB |
Output is correct |
7 |
Correct |
4 ms |
2424 KB |
Output is correct |
8 |
Correct |
4 ms |
2396 KB |
Output is correct |
9 |
Correct |
4 ms |
2424 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
5 ms |
2552 KB |
Output is correct |
12 |
Correct |
4 ms |
2540 KB |
Output is correct |
13 |
Correct |
5 ms |
2424 KB |
Output is correct |
14 |
Correct |
9 ms |
2684 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
5 ms |
2552 KB |
Output is correct |
17 |
Correct |
6 ms |
2808 KB |
Output is correct |
18 |
Correct |
5 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2580 KB |
Output is correct |
20 |
Correct |
5 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2552 KB |
Output is correct |
22 |
Correct |
5 ms |
2552 KB |
Output is correct |
23 |
Correct |
5 ms |
2680 KB |
Output is correct |
24 |
Correct |
6 ms |
2680 KB |
Output is correct |
25 |
Correct |
5 ms |
2680 KB |
Output is correct |
26 |
Correct |
5 ms |
2680 KB |
Output is correct |
27 |
Correct |
5 ms |
2552 KB |
Output is correct |
28 |
Correct |
5 ms |
2808 KB |
Output is correct |
29 |
Correct |
8 ms |
3320 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
6 ms |
2936 KB |
Output is correct |
32 |
Correct |
5 ms |
2808 KB |
Output is correct |
33 |
Correct |
10 ms |
3972 KB |
Output is correct |
34 |
Correct |
10 ms |
4084 KB |
Output is correct |
35 |
Correct |
25 ms |
4856 KB |
Output is correct |
36 |
Correct |
7 ms |
2936 KB |
Output is correct |
37 |
Correct |
28 ms |
5560 KB |
Output is correct |
38 |
Correct |
32 ms |
5880 KB |
Output is correct |
39 |
Correct |
35 ms |
6008 KB |
Output is correct |
40 |
Correct |
32 ms |
5984 KB |
Output is correct |
41 |
Correct |
33 ms |
5880 KB |
Output is correct |
42 |
Correct |
10 ms |
2808 KB |
Output is correct |
43 |
Correct |
9 ms |
2808 KB |
Output is correct |
44 |
Correct |
9 ms |
2808 KB |
Output is correct |
45 |
Correct |
34 ms |
8568 KB |
Output is correct |
46 |
Correct |
33 ms |
8588 KB |
Output is correct |
47 |
Correct |
66 ms |
13044 KB |
Output is correct |
48 |
Correct |
26 ms |
6260 KB |
Output is correct |
49 |
Correct |
19 ms |
5240 KB |
Output is correct |
50 |
Correct |
16 ms |
4856 KB |
Output is correct |
51 |
Correct |
53 ms |
8196 KB |
Output is correct |
52 |
Correct |
55 ms |
8696 KB |
Output is correct |
53 |
Correct |
26 ms |
5876 KB |
Output is correct |
54 |
Correct |
6 ms |
3064 KB |
Output is correct |
55 |
Correct |
7 ms |
3572 KB |
Output is correct |
56 |
Correct |
20 ms |
5240 KB |
Output is correct |
57 |
Correct |
46 ms |
11640 KB |
Output is correct |
58 |
Correct |
13 ms |
3696 KB |
Output is correct |
59 |
Correct |
14 ms |
4212 KB |
Output is correct |
60 |
Correct |
16 ms |
4852 KB |
Output is correct |
61 |
Correct |
16 ms |
4216 KB |
Output is correct |
62 |
Correct |
31 ms |
9460 KB |
Output is correct |
63 |
Correct |
95 ms |
26732 KB |
Output is correct |
64 |
Correct |
100 ms |
29932 KB |
Output is correct |
65 |
Correct |
132 ms |
39532 KB |
Output is correct |
66 |
Correct |
238 ms |
67816 KB |
Output is correct |
67 |
Correct |
243 ms |
67808 KB |
Output is correct |