#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const int N = 30000 + 11;
const int MAX = 2e9;
const int T = 1;
int dist[N],a[N],b[N];
bool use[N];
vector<int> v[N];
set<pair<int,int> > s[T+11];
int distt[T+11][N];
set<pair<int,int> > st;
void ups(int d, int l, int p)
{
if (dist[l]>p)
{
st.erase(mp(dist[l],l));
dist[l]=p;
st.insert(mp(dist[l],l));
}
if (distt[d][l]>p)
{
s[d].erase(mp(distt[d][l],l));
distt[d][l]=p;
s[d].insert(mp(distt[d][l],l));
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
int tt=0;
for (int i=1; i<=m; i++)
{
cin>>a[i]>>b[i];
a[i]++;
v[a[i]].pb(b[i]);
if (i==2) tt=a[i];
}
for (int p=1; p<=T; p++)
{
for (int i=1; i<=n; i++)
{
dist[i]=MAX;
distt[p][i]=MAX;
}
}
dist[a[1]]=0;
st.insert(mp(0,a[1]));
for (int ii=1; ii<=n; ii++)
{
for (int d=1; d<=T; d++)
while (s[d].size()>0)
{
pair<int,int> pp=*s[d].begin();
int to=pp.ss;
if (use[to]==1)
{
s[d].erase(mp(distt[d][to],to));
if (to-d>=1)
ups(d,to-d,distt[d][to]+1);
if (to+d<=n)
ups(d,to+d,distt[d][to]+1);
} else break;
}
pair<int,int> p=*st.begin();
st.erase(p);
int l=p.ss;
for (int t=0; t<v[l].size(); t++)
{
int x=v[l][t];
if (x>T)
{
for (int c=1; l+x*c<=n; c++)
if (dist[l+x*c]>dist[l]+c)
{
int to=l+x*c;
ups(0,to,dist[l]+c);
}
for (int c=1; l-x*c>=1; c++)
if (dist[l-x*c]>dist[l]+c)
{
int to=l-x*c;
ups(0,to,dist[l]+c);
}
} else
{
ups(x,l,dist[l]);
}
}
use[l]=1;
}
if (dist[tt]==MAX) cout<<-1<<endl;
else cout<<dist[tt]<<endl;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:79:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int t=0; t<v[l].size(); t++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1024 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1280 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
4 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1024 KB |
Output is correct |
2 |
Correct |
4 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1024 KB |
Output is correct |
7 |
Correct |
4 ms |
1024 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1124 KB |
Output is correct |
4 |
Correct |
4 ms |
1024 KB |
Output is correct |
5 |
Correct |
3 ms |
1024 KB |
Output is correct |
6 |
Correct |
3 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1024 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
4 ms |
1024 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
4 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1024 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
4 ms |
1148 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
4 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
6 ms |
1152 KB |
Output is correct |
25 |
Correct |
5 ms |
1280 KB |
Output is correct |
26 |
Correct |
4 ms |
1152 KB |
Output is correct |
27 |
Correct |
5 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1152 KB |
Output is correct |
29 |
Correct |
7 ms |
1280 KB |
Output is correct |
30 |
Correct |
4 ms |
1152 KB |
Output is correct |
31 |
Correct |
5 ms |
1280 KB |
Output is correct |
32 |
Correct |
4 ms |
1280 KB |
Output is correct |
33 |
Correct |
8 ms |
1280 KB |
Output is correct |
34 |
Correct |
7 ms |
1380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1024 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1024 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
3 ms |
1024 KB |
Output is correct |
10 |
Correct |
4 ms |
1024 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
4 ms |
1152 KB |
Output is correct |
14 |
Correct |
4 ms |
1152 KB |
Output is correct |
15 |
Correct |
4 ms |
1152 KB |
Output is correct |
16 |
Correct |
4 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
4 ms |
1152 KB |
Output is correct |
21 |
Correct |
5 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
5 ms |
1152 KB |
Output is correct |
24 |
Correct |
5 ms |
1280 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
4 ms |
1280 KB |
Output is correct |
27 |
Correct |
4 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1152 KB |
Output is correct |
29 |
Correct |
7 ms |
1152 KB |
Output is correct |
30 |
Correct |
4 ms |
1240 KB |
Output is correct |
31 |
Correct |
5 ms |
1152 KB |
Output is correct |
32 |
Correct |
5 ms |
1152 KB |
Output is correct |
33 |
Correct |
7 ms |
1280 KB |
Output is correct |
34 |
Correct |
7 ms |
1152 KB |
Output is correct |
35 |
Correct |
10 ms |
1792 KB |
Output is correct |
36 |
Correct |
6 ms |
1280 KB |
Output is correct |
37 |
Correct |
10 ms |
1664 KB |
Output is correct |
38 |
Correct |
13 ms |
1920 KB |
Output is correct |
39 |
Correct |
13 ms |
1920 KB |
Output is correct |
40 |
Correct |
13 ms |
1920 KB |
Output is correct |
41 |
Correct |
16 ms |
1920 KB |
Output is correct |
42 |
Correct |
13 ms |
1792 KB |
Output is correct |
43 |
Correct |
9 ms |
1792 KB |
Output is correct |
44 |
Correct |
10 ms |
1792 KB |
Output is correct |
45 |
Correct |
13 ms |
1792 KB |
Output is correct |
46 |
Correct |
14 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
3 ms |
1024 KB |
Output is correct |
5 |
Correct |
3 ms |
1024 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1024 KB |
Output is correct |
8 |
Correct |
4 ms |
1280 KB |
Output is correct |
9 |
Correct |
4 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1280 KB |
Output is correct |
11 |
Correct |
9 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
3 ms |
1152 KB |
Output is correct |
14 |
Correct |
4 ms |
1152 KB |
Output is correct |
15 |
Correct |
4 ms |
1152 KB |
Output is correct |
16 |
Correct |
2 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
4 ms |
1152 KB |
Output is correct |
21 |
Correct |
3 ms |
1148 KB |
Output is correct |
22 |
Correct |
3 ms |
1280 KB |
Output is correct |
23 |
Correct |
6 ms |
1152 KB |
Output is correct |
24 |
Correct |
5 ms |
1152 KB |
Output is correct |
25 |
Correct |
5 ms |
1280 KB |
Output is correct |
26 |
Correct |
5 ms |
1152 KB |
Output is correct |
27 |
Correct |
4 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1152 KB |
Output is correct |
29 |
Correct |
6 ms |
1152 KB |
Output is correct |
30 |
Correct |
4 ms |
1152 KB |
Output is correct |
31 |
Correct |
5 ms |
1152 KB |
Output is correct |
32 |
Correct |
5 ms |
1152 KB |
Output is correct |
33 |
Correct |
9 ms |
1280 KB |
Output is correct |
34 |
Correct |
7 ms |
1152 KB |
Output is correct |
35 |
Correct |
15 ms |
1792 KB |
Output is correct |
36 |
Correct |
5 ms |
1280 KB |
Output is correct |
37 |
Correct |
14 ms |
1664 KB |
Output is correct |
38 |
Correct |
16 ms |
1928 KB |
Output is correct |
39 |
Correct |
16 ms |
1920 KB |
Output is correct |
40 |
Correct |
13 ms |
1920 KB |
Output is correct |
41 |
Correct |
14 ms |
1920 KB |
Output is correct |
42 |
Correct |
10 ms |
1792 KB |
Output is correct |
43 |
Correct |
10 ms |
1792 KB |
Output is correct |
44 |
Correct |
9 ms |
1792 KB |
Output is correct |
45 |
Correct |
14 ms |
1792 KB |
Output is correct |
46 |
Correct |
14 ms |
1792 KB |
Output is correct |
47 |
Correct |
37 ms |
2432 KB |
Output is correct |
48 |
Correct |
13 ms |
2176 KB |
Output is correct |
49 |
Correct |
12 ms |
2176 KB |
Output is correct |
50 |
Correct |
12 ms |
1996 KB |
Output is correct |
51 |
Correct |
56 ms |
3328 KB |
Output is correct |
52 |
Correct |
76 ms |
3704 KB |
Output is correct |
53 |
Correct |
41 ms |
3320 KB |
Output is correct |
54 |
Correct |
9 ms |
2048 KB |
Output is correct |
55 |
Correct |
10 ms |
2048 KB |
Output is correct |
56 |
Correct |
19 ms |
2688 KB |
Output is correct |
57 |
Correct |
126 ms |
2808 KB |
Output is correct |
58 |
Correct |
17 ms |
2560 KB |
Output is correct |
59 |
Correct |
26 ms |
2688 KB |
Output is correct |
60 |
Correct |
21 ms |
2560 KB |
Output is correct |
61 |
Correct |
29 ms |
2688 KB |
Output is correct |
62 |
Correct |
24 ms |
2816 KB |
Output is correct |
63 |
Correct |
87 ms |
3320 KB |
Output is correct |
64 |
Correct |
85 ms |
3448 KB |
Output is correct |
65 |
Correct |
100 ms |
3352 KB |
Output is correct |
66 |
Correct |
165 ms |
3320 KB |
Output is correct |
67 |
Correct |
124 ms |
3308 KB |
Output is correct |