#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define all(x) x.begin(),x.end()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define p push
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int mxn=3*1e4,mod=998244353,lg=42,root=80,inf=1e9;
void setIO(string name) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int dist[(mxn*(root+1))+10];
vector<pii>adj[(mxn*(root+1))+10];
bitset<(mxn*(root+1))+10>vis;
int n,m;
//make dummy node
// n orginal + n node for each root(n)
//node more than root id = mxn*ith+starting point
void init(){
for(int i=1;i<=min(n,root);i++){
for(int j=0;j<n;j++){
adj[(mxn*i)+j].pb({j,0});//going down
}
for(int j=i;j<n;j++){
//buid=ld edge for each i
adj[(mxn*i)+j].pb({(mxn*i)+(j-i),1});
adj[(mxn*i)+(j-i)].pb({(mxn*i)+j,1});
}
}
}
int32_t main(){
fastio
cin>>n>>m;
int end;
init();
fill(dist,dist+(mxn*(root+1)),inf);
priority_queue<pii,vector<pii>,greater<pii>>pq;
for(int i=0;i<m;i++){
int st,p;cin>>st>>p;
if(i==1)end=st;
if(i==0)pq.push({0,st}),dist[st]=0;
if(p<=root)adj[st].pb({(p*mxn)+st,0});
else{
for(int j=1;(j*p)+st<n;j++){
adj[st].pb({(j*p)+st,j});
//adj[(j*p)+st].pb({st,j});
}
for(int j=1;st-(j*p)>=0;j++){
adj[st].pb({st-(j*p),j});
//adj[st-(j*p)].pb({st,j});
}
//connect normal edge
}
//input
}
//dijkstra
while(!pq.empty()){
int cur=pq.top().s;
pq.pop();
for(auto i:adj[cur]){
if(dist[i.f]>dist[cur]+i.s){
dist[i.f]=dist[cur]+i.s;
pq.push({dist[i.f],i.f});
}
}
}
cout<<((dist[end]==inf)?-1:dist[end]);
return 0;
}
Compilation message
skyscraper.cpp: In function 'void setIO(std::string)':
skyscraper.cpp:31:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:89:21: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
89 | cout<<((dist[end]==inf)?-1:dist[end]);
| ~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
66916 KB |
Output is correct |
2 |
Correct |
33 ms |
66900 KB |
Output is correct |
3 |
Correct |
29 ms |
66900 KB |
Output is correct |
4 |
Correct |
29 ms |
66772 KB |
Output is correct |
5 |
Correct |
29 ms |
66900 KB |
Output is correct |
6 |
Correct |
30 ms |
66900 KB |
Output is correct |
7 |
Correct |
30 ms |
66900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
66936 KB |
Output is correct |
2 |
Correct |
28 ms |
66868 KB |
Output is correct |
3 |
Correct |
30 ms |
66892 KB |
Output is correct |
4 |
Correct |
29 ms |
66900 KB |
Output is correct |
5 |
Correct |
29 ms |
66772 KB |
Output is correct |
6 |
Correct |
33 ms |
66764 KB |
Output is correct |
7 |
Correct |
29 ms |
66900 KB |
Output is correct |
8 |
Correct |
30 ms |
66900 KB |
Output is correct |
9 |
Correct |
29 ms |
67028 KB |
Output is correct |
10 |
Correct |
29 ms |
67156 KB |
Output is correct |
11 |
Correct |
31 ms |
67156 KB |
Output is correct |
12 |
Correct |
31 ms |
67156 KB |
Output is correct |
13 |
Correct |
30 ms |
67156 KB |
Output is correct |
14 |
Correct |
30 ms |
67156 KB |
Output is correct |
15 |
Correct |
30 ms |
67156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
66772 KB |
Output is correct |
2 |
Correct |
29 ms |
66884 KB |
Output is correct |
3 |
Correct |
29 ms |
66900 KB |
Output is correct |
4 |
Correct |
29 ms |
66772 KB |
Output is correct |
5 |
Correct |
29 ms |
66900 KB |
Output is correct |
6 |
Correct |
29 ms |
66804 KB |
Output is correct |
7 |
Correct |
29 ms |
66876 KB |
Output is correct |
8 |
Correct |
29 ms |
66892 KB |
Output is correct |
9 |
Correct |
30 ms |
66900 KB |
Output is correct |
10 |
Correct |
32 ms |
67156 KB |
Output is correct |
11 |
Correct |
30 ms |
67156 KB |
Output is correct |
12 |
Correct |
29 ms |
67156 KB |
Output is correct |
13 |
Correct |
30 ms |
67192 KB |
Output is correct |
14 |
Correct |
31 ms |
67140 KB |
Output is correct |
15 |
Correct |
32 ms |
67208 KB |
Output is correct |
16 |
Correct |
31 ms |
67560 KB |
Output is correct |
17 |
Correct |
36 ms |
69588 KB |
Output is correct |
18 |
Correct |
48 ms |
73416 KB |
Output is correct |
19 |
Correct |
44 ms |
74280 KB |
Output is correct |
20 |
Correct |
45 ms |
74316 KB |
Output is correct |
21 |
Correct |
32 ms |
68252 KB |
Output is correct |
22 |
Correct |
48 ms |
73428 KB |
Output is correct |
23 |
Correct |
41 ms |
72780 KB |
Output is correct |
24 |
Correct |
46 ms |
74060 KB |
Output is correct |
25 |
Correct |
45 ms |
74316 KB |
Output is correct |
26 |
Correct |
44 ms |
74316 KB |
Output is correct |
27 |
Correct |
45 ms |
74352 KB |
Output is correct |
28 |
Correct |
45 ms |
74324 KB |
Output is correct |
29 |
Correct |
47 ms |
74356 KB |
Output is correct |
30 |
Correct |
47 ms |
74360 KB |
Output is correct |
31 |
Correct |
46 ms |
74324 KB |
Output is correct |
32 |
Correct |
46 ms |
74316 KB |
Output is correct |
33 |
Correct |
51 ms |
74384 KB |
Output is correct |
34 |
Correct |
51 ms |
74316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
66900 KB |
Output is correct |
2 |
Correct |
29 ms |
66880 KB |
Output is correct |
3 |
Correct |
29 ms |
66900 KB |
Output is correct |
4 |
Correct |
30 ms |
66772 KB |
Output is correct |
5 |
Correct |
29 ms |
66900 KB |
Output is correct |
6 |
Correct |
29 ms |
66764 KB |
Output is correct |
7 |
Correct |
30 ms |
66900 KB |
Output is correct |
8 |
Correct |
30 ms |
66900 KB |
Output is correct |
9 |
Correct |
33 ms |
66892 KB |
Output is correct |
10 |
Correct |
34 ms |
67212 KB |
Output is correct |
11 |
Correct |
30 ms |
67152 KB |
Output is correct |
12 |
Correct |
30 ms |
67156 KB |
Output is correct |
13 |
Correct |
31 ms |
67156 KB |
Output is correct |
14 |
Correct |
31 ms |
67156 KB |
Output is correct |
15 |
Correct |
31 ms |
67156 KB |
Output is correct |
16 |
Correct |
31 ms |
67540 KB |
Output is correct |
17 |
Correct |
36 ms |
69620 KB |
Output is correct |
18 |
Correct |
44 ms |
73420 KB |
Output is correct |
19 |
Correct |
44 ms |
74316 KB |
Output is correct |
20 |
Correct |
44 ms |
74316 KB |
Output is correct |
21 |
Correct |
32 ms |
68180 KB |
Output is correct |
22 |
Correct |
42 ms |
73420 KB |
Output is correct |
23 |
Correct |
43 ms |
72780 KB |
Output is correct |
24 |
Correct |
45 ms |
73940 KB |
Output is correct |
25 |
Correct |
46 ms |
74356 KB |
Output is correct |
26 |
Correct |
46 ms |
74364 KB |
Output is correct |
27 |
Correct |
52 ms |
74316 KB |
Output is correct |
28 |
Correct |
46 ms |
74316 KB |
Output is correct |
29 |
Correct |
48 ms |
74312 KB |
Output is correct |
30 |
Correct |
55 ms |
74316 KB |
Output is correct |
31 |
Correct |
46 ms |
74316 KB |
Output is correct |
32 |
Correct |
47 ms |
74316 KB |
Output is correct |
33 |
Correct |
54 ms |
74316 KB |
Output is correct |
34 |
Correct |
51 ms |
74324 KB |
Output is correct |
35 |
Correct |
51 ms |
72660 KB |
Output is correct |
36 |
Correct |
40 ms |
70928 KB |
Output is correct |
37 |
Correct |
64 ms |
75188 KB |
Output is correct |
38 |
Correct |
63 ms |
75212 KB |
Output is correct |
39 |
Correct |
67 ms |
75280 KB |
Output is correct |
40 |
Correct |
64 ms |
75392 KB |
Output is correct |
41 |
Correct |
63 ms |
75256 KB |
Output is correct |
42 |
Correct |
48 ms |
74700 KB |
Output is correct |
43 |
Correct |
48 ms |
74700 KB |
Output is correct |
44 |
Correct |
53 ms |
74776 KB |
Output is correct |
45 |
Correct |
63 ms |
78044 KB |
Output is correct |
46 |
Correct |
64 ms |
78156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
66856 KB |
Output is correct |
2 |
Correct |
31 ms |
66772 KB |
Output is correct |
3 |
Correct |
30 ms |
66772 KB |
Output is correct |
4 |
Correct |
30 ms |
66772 KB |
Output is correct |
5 |
Correct |
34 ms |
66920 KB |
Output is correct |
6 |
Correct |
30 ms |
66900 KB |
Output is correct |
7 |
Correct |
30 ms |
66764 KB |
Output is correct |
8 |
Correct |
30 ms |
66900 KB |
Output is correct |
9 |
Correct |
30 ms |
66900 KB |
Output is correct |
10 |
Correct |
32 ms |
67168 KB |
Output is correct |
11 |
Correct |
31 ms |
67156 KB |
Output is correct |
12 |
Correct |
32 ms |
67156 KB |
Output is correct |
13 |
Correct |
30 ms |
67156 KB |
Output is correct |
14 |
Correct |
31 ms |
67156 KB |
Output is correct |
15 |
Correct |
32 ms |
67156 KB |
Output is correct |
16 |
Correct |
30 ms |
67540 KB |
Output is correct |
17 |
Correct |
36 ms |
69588 KB |
Output is correct |
18 |
Correct |
43 ms |
73420 KB |
Output is correct |
19 |
Correct |
46 ms |
74268 KB |
Output is correct |
20 |
Correct |
49 ms |
74372 KB |
Output is correct |
21 |
Correct |
32 ms |
68180 KB |
Output is correct |
22 |
Correct |
43 ms |
73468 KB |
Output is correct |
23 |
Correct |
43 ms |
72816 KB |
Output is correct |
24 |
Correct |
49 ms |
73932 KB |
Output is correct |
25 |
Correct |
52 ms |
74452 KB |
Output is correct |
26 |
Correct |
45 ms |
74256 KB |
Output is correct |
27 |
Correct |
47 ms |
74316 KB |
Output is correct |
28 |
Correct |
47 ms |
74324 KB |
Output is correct |
29 |
Correct |
48 ms |
74316 KB |
Output is correct |
30 |
Correct |
46 ms |
74316 KB |
Output is correct |
31 |
Correct |
48 ms |
74364 KB |
Output is correct |
32 |
Correct |
46 ms |
74320 KB |
Output is correct |
33 |
Correct |
52 ms |
74388 KB |
Output is correct |
34 |
Correct |
52 ms |
74324 KB |
Output is correct |
35 |
Correct |
52 ms |
72660 KB |
Output is correct |
36 |
Correct |
39 ms |
70860 KB |
Output is correct |
37 |
Correct |
62 ms |
75252 KB |
Output is correct |
38 |
Correct |
63 ms |
75212 KB |
Output is correct |
39 |
Correct |
63 ms |
75220 KB |
Output is correct |
40 |
Correct |
62 ms |
75288 KB |
Output is correct |
41 |
Correct |
70 ms |
75324 KB |
Output is correct |
42 |
Correct |
47 ms |
74708 KB |
Output is correct |
43 |
Correct |
47 ms |
74700 KB |
Output is correct |
44 |
Correct |
48 ms |
74628 KB |
Output is correct |
45 |
Correct |
63 ms |
78156 KB |
Output is correct |
46 |
Correct |
65 ms |
78276 KB |
Output is correct |
47 |
Correct |
259 ms |
118220 KB |
Output is correct |
48 |
Correct |
217 ms |
155340 KB |
Output is correct |
49 |
Correct |
249 ms |
163252 KB |
Output is correct |
50 |
Correct |
261 ms |
172624 KB |
Output is correct |
51 |
Correct |
323 ms |
181736 KB |
Output is correct |
52 |
Correct |
318 ms |
181836 KB |
Output is correct |
53 |
Correct |
277 ms |
179572 KB |
Output is correct |
54 |
Correct |
272 ms |
179432 KB |
Output is correct |
55 |
Correct |
267 ms |
179516 KB |
Output is correct |
56 |
Correct |
271 ms |
180572 KB |
Output is correct |
57 |
Correct |
345 ms |
179620 KB |
Output is correct |
58 |
Correct |
269 ms |
179812 KB |
Output is correct |
59 |
Correct |
284 ms |
179908 KB |
Output is correct |
60 |
Correct |
306 ms |
180428 KB |
Output is correct |
61 |
Correct |
301 ms |
180136 KB |
Output is correct |
62 |
Correct |
288 ms |
182372 KB |
Output is correct |
63 |
Correct |
337 ms |
204376 KB |
Output is correct |
64 |
Correct |
344 ms |
212292 KB |
Output is correct |
65 |
Correct |
368 ms |
218664 KB |
Output is correct |
66 |
Correct |
553 ms |
225440 KB |
Output is correct |
67 |
Correct |
556 ms |
225412 KB |
Output is correct |