#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
//const int mod = 1000000007;
//Note to self: Check for overflow
bool vis[30003];
set<int> psi[30003];
vector<pii> g[30003];
int main()
{
FAST;
int n,m; cin>>n>>m;
set<pii> doges;
int s,t;
ff(i,0,m)
{
int b,p; cin>>b>>p;
doges.insert({b,p});
if (i==0) s=b;
if (i==1) t=b;
}
for (auto [b,p] : doges) psi[b].insert(-p);
vector<bool> tempvis(n,0);
ff(i,0,n)
{
for (auto __jmp : psi[i])
{
int jmp=-__jmp;
int tez=1;
int tit=i;
while (true)
{
int got=tit+jmp;
if (got>=n) break;
if (!tempvis[got] && !psi[got].empty()) g[i].pb({got,tez}),tempvis[got]=true;
tit=got,tez++;
if (psi[tit].count(__jmp)) break;
}
tez=1;
tit=i;
while (true)
{
int got=tit-jmp;
if (got<0) break;
if (!tempvis[got] && !psi[got].empty()) g[i].pb({got,tez}),tempvis[got]=true;
tit=got,tez++;
if (psi[tit].count(__jmp)) break;
}
}
for (auto sta : g[i]) tempvis[sta.xx]=0;
}
priority_queue<pii,vector<pii>,greater<pii>> pq;
pq.push({0,s});
while (!pq.empty())
{
auto [d,p]=pq.top(); pq.pop();
if (vis[p]) continue; vis[p]=1;
if (p==t) return cout<<d,0;
for (auto [it,w] : g[p]) if (!vis[it]) pq.push({w+d,it});
}
cout<<-1;
}
//Note to self: Check for overflow
/*
5 3
0 2
1 1
4 1
*/
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | for (auto [b,p] : doges) psi[b].insert(-p);
| ^
skyscraper.cpp:98:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
98 | auto [d,p]=pq.top(); pq.pop();
| ^
skyscraper.cpp:99:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
99 | if (vis[p]) continue; vis[p]=1;
| ^~
skyscraper.cpp:99:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
99 | if (vis[p]) continue; vis[p]=1;
| ^~~
skyscraper.cpp:102:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
102 | for (auto [it,w] : g[p]) if (!vis[it]) pq.push({w+d,it});
| ^
skyscraper.cpp:100:9: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
100 | if (p==t) return cout<<d,0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2388 KB |
Output is correct |
2 |
Correct |
2 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2388 KB |
Output is correct |
6 |
Correct |
1 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
2 ms |
2388 KB |
Output is correct |
4 |
Correct |
2 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2388 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
2388 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Correct |
2 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
2 ms |
2388 KB |
Output is correct |
9 |
Correct |
1 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2388 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2516 KB |
Output is correct |
17 |
Correct |
3 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2516 KB |
Output is correct |
19 |
Correct |
3 ms |
2388 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2560 KB |
Output is correct |
22 |
Correct |
2 ms |
2516 KB |
Output is correct |
23 |
Correct |
2 ms |
2516 KB |
Output is correct |
24 |
Correct |
3 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2388 KB |
Output is correct |
27 |
Correct |
2 ms |
2388 KB |
Output is correct |
28 |
Correct |
3 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2516 KB |
Output is correct |
30 |
Correct |
2 ms |
2388 KB |
Output is correct |
31 |
Correct |
2 ms |
2388 KB |
Output is correct |
32 |
Correct |
2 ms |
2388 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
4 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
2 ms |
2388 KB |
Output is correct |
3 |
Correct |
2 ms |
2388 KB |
Output is correct |
4 |
Correct |
2 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2400 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
1 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2388 KB |
Output is correct |
11 |
Correct |
3 ms |
2516 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
3 ms |
2388 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2516 KB |
Output is correct |
17 |
Correct |
3 ms |
2772 KB |
Output is correct |
18 |
Correct |
3 ms |
2516 KB |
Output is correct |
19 |
Correct |
2 ms |
2388 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2516 KB |
Output is correct |
22 |
Correct |
1 ms |
2516 KB |
Output is correct |
23 |
Correct |
2 ms |
2620 KB |
Output is correct |
24 |
Correct |
3 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2388 KB |
Output is correct |
27 |
Correct |
2 ms |
2388 KB |
Output is correct |
28 |
Correct |
3 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2516 KB |
Output is correct |
30 |
Correct |
2 ms |
2388 KB |
Output is correct |
31 |
Correct |
2 ms |
2388 KB |
Output is correct |
32 |
Correct |
3 ms |
2388 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
3 ms |
2644 KB |
Output is correct |
35 |
Correct |
23 ms |
6352 KB |
Output is correct |
36 |
Correct |
4 ms |
3028 KB |
Output is correct |
37 |
Correct |
25 ms |
7280 KB |
Output is correct |
38 |
Correct |
26 ms |
7412 KB |
Output is correct |
39 |
Correct |
26 ms |
6884 KB |
Output is correct |
40 |
Correct |
30 ms |
6996 KB |
Output is correct |
41 |
Correct |
33 ms |
7116 KB |
Output is correct |
42 |
Correct |
8 ms |
2388 KB |
Output is correct |
43 |
Correct |
6 ms |
2388 KB |
Output is correct |
44 |
Correct |
9 ms |
2692 KB |
Output is correct |
45 |
Correct |
21 ms |
5588 KB |
Output is correct |
46 |
Correct |
20 ms |
5588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Correct |
1 ms |
2388 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2388 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
2 ms |
2388 KB |
Output is correct |
8 |
Correct |
1 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
2 ms |
2388 KB |
Output is correct |
11 |
Correct |
3 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
1 ms |
2388 KB |
Output is correct |
14 |
Correct |
3 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2656 KB |
Output is correct |
16 |
Correct |
2 ms |
2516 KB |
Output is correct |
17 |
Correct |
3 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2516 KB |
Output is correct |
19 |
Correct |
2 ms |
2388 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2516 KB |
Output is correct |
22 |
Correct |
2 ms |
2516 KB |
Output is correct |
23 |
Correct |
2 ms |
2516 KB |
Output is correct |
24 |
Correct |
4 ms |
2644 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2388 KB |
Output is correct |
27 |
Correct |
2 ms |
2388 KB |
Output is correct |
28 |
Correct |
3 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2516 KB |
Output is correct |
30 |
Correct |
1 ms |
2388 KB |
Output is correct |
31 |
Correct |
1 ms |
2388 KB |
Output is correct |
32 |
Correct |
2 ms |
2388 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
3 ms |
2644 KB |
Output is correct |
35 |
Correct |
26 ms |
6352 KB |
Output is correct |
36 |
Correct |
4 ms |
2996 KB |
Output is correct |
37 |
Correct |
25 ms |
7304 KB |
Output is correct |
38 |
Correct |
30 ms |
7524 KB |
Output is correct |
39 |
Correct |
29 ms |
6792 KB |
Output is correct |
40 |
Correct |
25 ms |
6892 KB |
Output is correct |
41 |
Correct |
26 ms |
6996 KB |
Output is correct |
42 |
Correct |
6 ms |
2440 KB |
Output is correct |
43 |
Correct |
6 ms |
2388 KB |
Output is correct |
44 |
Correct |
6 ms |
2644 KB |
Output is correct |
45 |
Correct |
21 ms |
5652 KB |
Output is correct |
46 |
Correct |
21 ms |
5584 KB |
Output is correct |
47 |
Correct |
46 ms |
14160 KB |
Output is correct |
48 |
Correct |
19 ms |
6024 KB |
Output is correct |
49 |
Correct |
19 ms |
5332 KB |
Output is correct |
50 |
Correct |
12 ms |
4480 KB |
Output is correct |
51 |
Correct |
34 ms |
8540 KB |
Output is correct |
52 |
Correct |
45 ms |
8884 KB |
Output is correct |
53 |
Correct |
30 ms |
6004 KB |
Output is correct |
54 |
Correct |
2 ms |
2388 KB |
Output is correct |
55 |
Correct |
2 ms |
2388 KB |
Output is correct |
56 |
Correct |
19 ms |
6336 KB |
Output is correct |
57 |
Correct |
7 ms |
3268 KB |
Output is correct |
58 |
Correct |
5 ms |
2516 KB |
Output is correct |
59 |
Correct |
6 ms |
2572 KB |
Output is correct |
60 |
Correct |
7 ms |
2692 KB |
Output is correct |
61 |
Correct |
7 ms |
3028 KB |
Output is correct |
62 |
Correct |
37 ms |
10632 KB |
Output is correct |
63 |
Correct |
38 ms |
5628 KB |
Output is correct |
64 |
Correct |
32 ms |
5624 KB |
Output is correct |
65 |
Correct |
35 ms |
5668 KB |
Output is correct |
66 |
Correct |
48 ms |
5856 KB |
Output is correct |
67 |
Correct |
43 ms |
5876 KB |
Output is correct |