/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#pragma GCC optimization ("O3")
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
int n=nxt(),m=nxt();
vector<pair<int,int> >v;
map<pair<int,int>,int>mp;
for(int i=0;i<m;i++){
int b=nxt(),p=nxt();
v.push_back({b,p});
}
int from = v[0].first,to = v[1].first;
vector<pair<int,int> >v2;
sort(all(v));
for(int i=0;i<m;i++){
if(v2.size()&&v2.back()==v[i])continue;
v2.push_back(v[i]);
}
v=v2;
vector<pair<int,int> >adj[n+1];
for(int i=0;i<v.size();i++){
for(int j=v[i].first+v[i].second;j<n;j+=v[i].second){
adj[v[i].first].push_back({j,(j-v[i].first)/v[i].second});
if(mp[{j,v[i].second}])break;
}
}
for(int i=0;i<v.size();i++){
for(int j=v[i].first-v[i].second;j>=0;j-=v[i].second){
adj[v[i].first].push_back({j,(v[i].first-j)/v[i].second});
if(mp[{j,v[i].second}])break;
}
}
int dis[n],vis[n];
for(int i=0;i<n;i++)
dis[i]=INF,vis[i]=0;
dis[from]=0;
priority_queue<pair<int,int> >q;
q.push({0,from});
while(!q.empty()) {
int a=q.top().second;q.pop();
if(vis[a])continue;
vis[a]=1;
for(auto u:adj[a]){
int b=u.first,w=u.second;
if(dis[a]+w<dis[b]){
dis[b]=dis[a]+w;
q.push({-dis[b],b});
}
}
}
if(dis[to]==INF)cout<<-1<<endl;
else cout<<dis[to]<<endl;
return 0;
}
Compilation message
skyscraper.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
11 | #pragma GCC optimization ("O3")
|
skyscraper.cpp:21:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
21 | const int mo=1e9+7,INF=1e18;
| ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
skyscraper.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
268 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
1356 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
248 ms |
32736 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
3 ms |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
1228 KB |
Output is correct |
25 |
Correct |
3 ms |
844 KB |
Output is correct |
26 |
Correct |
3 ms |
972 KB |
Output is correct |
27 |
Correct |
2 ms |
844 KB |
Output is correct |
28 |
Correct |
7 ms |
1896 KB |
Output is correct |
29 |
Correct |
25 ms |
4960 KB |
Output is correct |
30 |
Correct |
6 ms |
1740 KB |
Output is correct |
31 |
Correct |
12 ms |
2764 KB |
Output is correct |
32 |
Correct |
8 ms |
2124 KB |
Output is correct |
33 |
Correct |
55 ms |
9028 KB |
Output is correct |
34 |
Correct |
69 ms |
9076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
1356 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
250 ms |
32608 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
1228 KB |
Output is correct |
25 |
Correct |
3 ms |
844 KB |
Output is correct |
26 |
Correct |
3 ms |
972 KB |
Output is correct |
27 |
Correct |
2 ms |
844 KB |
Output is correct |
28 |
Correct |
7 ms |
1868 KB |
Output is correct |
29 |
Correct |
23 ms |
4828 KB |
Output is correct |
30 |
Correct |
7 ms |
1868 KB |
Output is correct |
31 |
Correct |
15 ms |
2764 KB |
Output is correct |
32 |
Correct |
9 ms |
2044 KB |
Output is correct |
33 |
Correct |
58 ms |
9124 KB |
Output is correct |
34 |
Correct |
57 ms |
9052 KB |
Output is correct |
35 |
Correct |
50 ms |
7108 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
114 ms |
13420 KB |
Output is correct |
38 |
Correct |
98 ms |
11604 KB |
Output is correct |
39 |
Correct |
100 ms |
11696 KB |
Output is correct |
40 |
Correct |
109 ms |
11620 KB |
Output is correct |
41 |
Correct |
95 ms |
11424 KB |
Output is correct |
42 |
Correct |
9 ms |
1232 KB |
Output is correct |
43 |
Correct |
8 ms |
976 KB |
Output is correct |
44 |
Correct |
277 ms |
32920 KB |
Output is correct |
45 |
Correct |
359 ms |
33456 KB |
Output is correct |
46 |
Correct |
345 ms |
33392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
1356 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
251 ms |
32572 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
3 ms |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
1228 KB |
Output is correct |
25 |
Correct |
3 ms |
844 KB |
Output is correct |
26 |
Correct |
3 ms |
972 KB |
Output is correct |
27 |
Correct |
2 ms |
844 KB |
Output is correct |
28 |
Correct |
7 ms |
1868 KB |
Output is correct |
29 |
Correct |
23 ms |
4848 KB |
Output is correct |
30 |
Correct |
6 ms |
1740 KB |
Output is correct |
31 |
Correct |
11 ms |
2764 KB |
Output is correct |
32 |
Correct |
8 ms |
2124 KB |
Output is correct |
33 |
Correct |
49 ms |
9120 KB |
Output is correct |
34 |
Correct |
52 ms |
9072 KB |
Output is correct |
35 |
Correct |
53 ms |
7108 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
115 ms |
13440 KB |
Output is correct |
38 |
Correct |
92 ms |
11536 KB |
Output is correct |
39 |
Correct |
92 ms |
11712 KB |
Output is correct |
40 |
Correct |
94 ms |
11588 KB |
Output is correct |
41 |
Correct |
85 ms |
11440 KB |
Output is correct |
42 |
Correct |
8 ms |
1232 KB |
Output is correct |
43 |
Correct |
8 ms |
1052 KB |
Output is correct |
44 |
Correct |
278 ms |
32892 KB |
Output is correct |
45 |
Correct |
398 ms |
33480 KB |
Output is correct |
46 |
Correct |
309 ms |
33480 KB |
Output is correct |
47 |
Correct |
743 ms |
56896 KB |
Output is correct |
48 |
Correct |
125 ms |
16964 KB |
Output is correct |
49 |
Correct |
62 ms |
10556 KB |
Output is correct |
50 |
Correct |
71 ms |
10992 KB |
Output is correct |
51 |
Correct |
200 ms |
24484 KB |
Output is correct |
52 |
Correct |
225 ms |
26316 KB |
Output is correct |
53 |
Correct |
31 ms |
6892 KB |
Output is correct |
54 |
Correct |
9 ms |
3532 KB |
Output is correct |
55 |
Correct |
17 ms |
5544 KB |
Output is correct |
56 |
Execution timed out |
1086 ms |
80656 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |