#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e4+5;
const ll inf=2e18;
int n,m,b[maxN+1],p[maxN+1];
namespace sub4
{
const int LIMIT=4e3+5;
int d[LIMIT+1][LIMIT+1];
struct node
{
int u,power;
};
deque<node> q;
vector<int> cprs;
vector<pii> adj[LIMIT+1];
int nen(int x)
{
return lower_bound(cprs.begin(),cprs.end(),x)-cprs.begin();
}
void solve()
{
for(int i=0;i<LIMIT;i++)
{
for(int j=0;j<LIMIT;j++)
{
d[i][j]=inf;
}
}
for(int i=0;i<m;i++)
{
cprs.push_back(b[i]);
}
sort(cprs.begin(),cprs.end());
cprs.resize(unique(cprs.begin(),cprs.end())-cprs.begin());
for(int i=0;i<m;i++)
{
int x=n+nen(b[i]);
adj[x].push_back({b[i],p[i]});
adj[b[i]].push_back({x,0});
}
q.push_front({b[0],p[0]});
d[b[0]][p[0]]=0;
while(!q.empty())
{
node tmp=q.front();
q.pop_front();
int u=tmp.u,power=tmp.power;
//cout<<u<<" "<<power<<'\n';
if(u==b[1])
{
cout<<d[u][power];
return;
}
if(u<n)
{
if(u+power<n)
{
if(d[u+power][power]>d[u][power]+1)
{
d[u+power][power]=d[u][power]+1;
q.push_back({u+power,power});
}
}
if(u-power>=0)
{
if(d[u-power][power]>d[u][power]+1)
{
d[u-power][power]=d[u][power]+1;
q.push_back({u-power,power});
}
}
}
for(auto i:adj[u])
{
if(d[i.fi][i.se]>d[u][power])
{
d[i.fi][i.se]=d[u][power];
q.push_front({i.fi,i.se});
}
}
}
cout<<-1;
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>b[i]>>p[i];
}
sub4::solve();
}
Compilation message
skyscraper.cpp: In function 'void sub4::solve()':
skyscraper.cpp:32:25: warning: overflow in conversion from 'long long int' to 'int' changes value from '2000000000000000000' to '1321730048' [-Woverflow]
32 | d[i][j]=inf;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
63316 KB |
Output is correct |
2 |
Correct |
30 ms |
63248 KB |
Output is correct |
3 |
Correct |
29 ms |
63312 KB |
Output is correct |
4 |
Correct |
29 ms |
63320 KB |
Output is correct |
5 |
Correct |
29 ms |
63320 KB |
Output is correct |
6 |
Correct |
29 ms |
63316 KB |
Output is correct |
7 |
Correct |
30 ms |
63316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
63324 KB |
Output is correct |
2 |
Correct |
29 ms |
63112 KB |
Output is correct |
3 |
Correct |
29 ms |
63316 KB |
Output is correct |
4 |
Correct |
29 ms |
63116 KB |
Output is correct |
5 |
Correct |
28 ms |
63316 KB |
Output is correct |
6 |
Correct |
28 ms |
63324 KB |
Output is correct |
7 |
Correct |
36 ms |
63324 KB |
Output is correct |
8 |
Correct |
39 ms |
63316 KB |
Output is correct |
9 |
Correct |
31 ms |
63312 KB |
Output is correct |
10 |
Correct |
37 ms |
63316 KB |
Output is correct |
11 |
Correct |
29 ms |
63312 KB |
Output is correct |
12 |
Correct |
26 ms |
63312 KB |
Output is correct |
13 |
Correct |
27 ms |
63316 KB |
Output is correct |
14 |
Correct |
26 ms |
63324 KB |
Output is correct |
15 |
Correct |
25 ms |
63324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
63324 KB |
Output is correct |
2 |
Correct |
25 ms |
63324 KB |
Output is correct |
3 |
Correct |
26 ms |
63324 KB |
Output is correct |
4 |
Correct |
28 ms |
63312 KB |
Output is correct |
5 |
Correct |
28 ms |
63316 KB |
Output is correct |
6 |
Correct |
34 ms |
63316 KB |
Output is correct |
7 |
Correct |
28 ms |
63324 KB |
Output is correct |
8 |
Correct |
36 ms |
63108 KB |
Output is correct |
9 |
Correct |
27 ms |
63324 KB |
Output is correct |
10 |
Correct |
27 ms |
63184 KB |
Output is correct |
11 |
Correct |
27 ms |
63368 KB |
Output is correct |
12 |
Correct |
28 ms |
63316 KB |
Output is correct |
13 |
Correct |
27 ms |
63264 KB |
Output is correct |
14 |
Correct |
28 ms |
63432 KB |
Output is correct |
15 |
Correct |
28 ms |
63316 KB |
Output is correct |
16 |
Correct |
27 ms |
63368 KB |
Output is correct |
17 |
Correct |
27 ms |
63276 KB |
Output is correct |
18 |
Correct |
27 ms |
63324 KB |
Output is correct |
19 |
Correct |
28 ms |
63576 KB |
Output is correct |
20 |
Correct |
27 ms |
63472 KB |
Output is correct |
21 |
Correct |
29 ms |
63268 KB |
Output is correct |
22 |
Correct |
27 ms |
63320 KB |
Output is correct |
23 |
Correct |
27 ms |
63324 KB |
Output is correct |
24 |
Correct |
28 ms |
63316 KB |
Output is correct |
25 |
Correct |
27 ms |
63340 KB |
Output is correct |
26 |
Correct |
27 ms |
63320 KB |
Output is correct |
27 |
Correct |
26 ms |
63332 KB |
Output is correct |
28 |
Correct |
29 ms |
63320 KB |
Output is correct |
29 |
Correct |
30 ms |
63344 KB |
Output is correct |
30 |
Correct |
28 ms |
63324 KB |
Output is correct |
31 |
Correct |
28 ms |
63324 KB |
Output is correct |
32 |
Correct |
28 ms |
63324 KB |
Output is correct |
33 |
Correct |
30 ms |
63312 KB |
Output is correct |
34 |
Correct |
29 ms |
63312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
63320 KB |
Output is correct |
2 |
Correct |
28 ms |
63100 KB |
Output is correct |
3 |
Correct |
27 ms |
63324 KB |
Output is correct |
4 |
Correct |
27 ms |
63336 KB |
Output is correct |
5 |
Correct |
27 ms |
63324 KB |
Output is correct |
6 |
Correct |
26 ms |
63324 KB |
Output is correct |
7 |
Correct |
28 ms |
63324 KB |
Output is correct |
8 |
Correct |
27 ms |
63316 KB |
Output is correct |
9 |
Correct |
29 ms |
63316 KB |
Output is correct |
10 |
Correct |
27 ms |
63256 KB |
Output is correct |
11 |
Correct |
27 ms |
63324 KB |
Output is correct |
12 |
Correct |
26 ms |
63324 KB |
Output is correct |
13 |
Correct |
28 ms |
63324 KB |
Output is correct |
14 |
Correct |
28 ms |
63232 KB |
Output is correct |
15 |
Correct |
28 ms |
63312 KB |
Output is correct |
16 |
Correct |
27 ms |
63324 KB |
Output is correct |
17 |
Correct |
29 ms |
63316 KB |
Output is correct |
18 |
Correct |
33 ms |
63312 KB |
Output is correct |
19 |
Correct |
27 ms |
63320 KB |
Output is correct |
20 |
Correct |
28 ms |
63324 KB |
Output is correct |
21 |
Correct |
28 ms |
63312 KB |
Output is correct |
22 |
Correct |
34 ms |
63316 KB |
Output is correct |
23 |
Correct |
28 ms |
63316 KB |
Output is correct |
24 |
Correct |
37 ms |
63312 KB |
Output is correct |
25 |
Correct |
28 ms |
63424 KB |
Output is correct |
26 |
Correct |
27 ms |
63316 KB |
Output is correct |
27 |
Correct |
28 ms |
63312 KB |
Output is correct |
28 |
Correct |
29 ms |
63324 KB |
Output is correct |
29 |
Correct |
29 ms |
63304 KB |
Output is correct |
30 |
Correct |
29 ms |
63332 KB |
Output is correct |
31 |
Correct |
29 ms |
63312 KB |
Output is correct |
32 |
Correct |
28 ms |
63156 KB |
Output is correct |
33 |
Correct |
29 ms |
63316 KB |
Output is correct |
34 |
Correct |
29 ms |
63320 KB |
Output is correct |
35 |
Correct |
38 ms |
64596 KB |
Output is correct |
36 |
Correct |
28 ms |
63572 KB |
Output is correct |
37 |
Correct |
35 ms |
64376 KB |
Output is correct |
38 |
Correct |
40 ms |
64852 KB |
Output is correct |
39 |
Correct |
35 ms |
64680 KB |
Output is correct |
40 |
Correct |
36 ms |
64596 KB |
Output is correct |
41 |
Correct |
36 ms |
64708 KB |
Output is correct |
42 |
Correct |
32 ms |
64528 KB |
Output is correct |
43 |
Correct |
31 ms |
64540 KB |
Output is correct |
44 |
Correct |
31 ms |
64584 KB |
Output is correct |
45 |
Correct |
50 ms |
64596 KB |
Output is correct |
46 |
Correct |
44 ms |
64596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
63316 KB |
Output is correct |
2 |
Correct |
27 ms |
63252 KB |
Output is correct |
3 |
Correct |
28 ms |
63316 KB |
Output is correct |
4 |
Correct |
36 ms |
63308 KB |
Output is correct |
5 |
Correct |
28 ms |
63324 KB |
Output is correct |
6 |
Correct |
27 ms |
63240 KB |
Output is correct |
7 |
Correct |
29 ms |
63316 KB |
Output is correct |
8 |
Correct |
27 ms |
63312 KB |
Output is correct |
9 |
Correct |
28 ms |
63324 KB |
Output is correct |
10 |
Correct |
34 ms |
63212 KB |
Output is correct |
11 |
Correct |
28 ms |
63408 KB |
Output is correct |
12 |
Correct |
27 ms |
63312 KB |
Output is correct |
13 |
Correct |
28 ms |
63312 KB |
Output is correct |
14 |
Correct |
28 ms |
63316 KB |
Output is correct |
15 |
Correct |
28 ms |
63428 KB |
Output is correct |
16 |
Correct |
27 ms |
63312 KB |
Output is correct |
17 |
Correct |
28 ms |
63324 KB |
Output is correct |
18 |
Correct |
27 ms |
63312 KB |
Output is correct |
19 |
Correct |
34 ms |
63388 KB |
Output is correct |
20 |
Correct |
28 ms |
63320 KB |
Output is correct |
21 |
Correct |
26 ms |
63312 KB |
Output is correct |
22 |
Correct |
27 ms |
63316 KB |
Output is correct |
23 |
Correct |
28 ms |
63316 KB |
Output is correct |
24 |
Correct |
31 ms |
63316 KB |
Output is correct |
25 |
Correct |
29 ms |
63312 KB |
Output is correct |
26 |
Correct |
27 ms |
63268 KB |
Output is correct |
27 |
Correct |
28 ms |
63320 KB |
Output is correct |
28 |
Correct |
32 ms |
63452 KB |
Output is correct |
29 |
Correct |
30 ms |
63216 KB |
Output is correct |
30 |
Correct |
28 ms |
63316 KB |
Output is correct |
31 |
Correct |
29 ms |
63296 KB |
Output is correct |
32 |
Correct |
29 ms |
63316 KB |
Output is correct |
33 |
Correct |
31 ms |
63316 KB |
Output is correct |
34 |
Correct |
30 ms |
63316 KB |
Output is correct |
35 |
Correct |
39 ms |
64604 KB |
Output is correct |
36 |
Correct |
29 ms |
63568 KB |
Output is correct |
37 |
Correct |
33 ms |
64340 KB |
Output is correct |
38 |
Correct |
37 ms |
64852 KB |
Output is correct |
39 |
Correct |
35 ms |
64604 KB |
Output is correct |
40 |
Correct |
37 ms |
64592 KB |
Output is correct |
41 |
Correct |
36 ms |
64596 KB |
Output is correct |
42 |
Correct |
32 ms |
64540 KB |
Output is correct |
43 |
Correct |
29 ms |
64480 KB |
Output is correct |
44 |
Correct |
31 ms |
64596 KB |
Output is correct |
45 |
Correct |
57 ms |
64600 KB |
Output is correct |
46 |
Correct |
44 ms |
64596 KB |
Output is correct |
47 |
Runtime error |
82 ms |
129016 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |