#include <bits/stdc++.h>
using namespace std;
int n,p[30004],b[30004],m;
priority_queue <pair<int,int> ,vector <pair<int,int> >,greater <pair<int,int> > > pq;
bool vis[30004];
vector <int> v[30004];
int cur[30004];
void dij()
{
for (int i=0;i<n;i++)
cur[i]=INT_MAX;
cur[b[0]]=0;
pq.push({0,b[0]});
while (!pq.empty())
{
int x= (pq.top()).second;
int y= (pq.top()).first;
pq.pop();
if (vis[x])
continue;
vis[x]=true;
for (int i=0;i<v[x].size();i++)
{
for (int j=0;j*v[x][i]+x<n;j++)
{
int a= (j*v[x][i]+x);
if (cur[a]>y+j)
{
cur[a]=y+j;
pq.push({cur[a],a});
}
}
for (int j=1;x-j*v[x][i]>=0;j++)
{
int a= (x-j*v[x][i]);
if (cur[a]>y+j)
{
cur[a]=y+j;
pq.push({cur[a],a});
}
}
}
}
}
int main()
{
cin >>n>>m;
for (int i=0;i<m;i++)
{
cin >>b[i]>>p[i];
v[b[i]].push_back(p[i]);
}
dij();
if (!vis[b[1]])
cout <<-1;
else
cout <<cur[b[1]];
return 0;
}
Compilation message
skyscraper.cpp: In function 'void dij()':
skyscraper.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[x].size();i++)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1044 KB |
Output is correct |
4 |
Correct |
2 ms |
1228 KB |
Output is correct |
5 |
Correct |
3 ms |
1228 KB |
Output is correct |
6 |
Correct |
2 ms |
1228 KB |
Output is correct |
7 |
Correct |
3 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1292 KB |
Output is correct |
3 |
Correct |
2 ms |
1292 KB |
Output is correct |
4 |
Correct |
2 ms |
1292 KB |
Output is correct |
5 |
Correct |
2 ms |
1292 KB |
Output is correct |
6 |
Correct |
2 ms |
1292 KB |
Output is correct |
7 |
Correct |
2 ms |
1292 KB |
Output is correct |
8 |
Correct |
2 ms |
1292 KB |
Output is correct |
9 |
Correct |
2 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
1292 KB |
Output is correct |
11 |
Correct |
3 ms |
1292 KB |
Output is correct |
12 |
Correct |
3 ms |
1292 KB |
Output is correct |
13 |
Correct |
3 ms |
1320 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1372 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
3 ms |
1372 KB |
Output is correct |
6 |
Correct |
2 ms |
1372 KB |
Output is correct |
7 |
Correct |
2 ms |
1372 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
2 ms |
1372 KB |
Output is correct |
10 |
Correct |
2 ms |
1372 KB |
Output is correct |
11 |
Correct |
3 ms |
1372 KB |
Output is correct |
12 |
Correct |
3 ms |
1372 KB |
Output is correct |
13 |
Correct |
3 ms |
1372 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
3 ms |
1372 KB |
Output is correct |
16 |
Correct |
3 ms |
1372 KB |
Output is correct |
17 |
Correct |
3 ms |
1388 KB |
Output is correct |
18 |
Correct |
3 ms |
1388 KB |
Output is correct |
19 |
Correct |
2 ms |
1388 KB |
Output is correct |
20 |
Correct |
9 ms |
1388 KB |
Output is correct |
21 |
Correct |
3 ms |
1388 KB |
Output is correct |
22 |
Correct |
3 ms |
1388 KB |
Output is correct |
23 |
Correct |
3 ms |
1388 KB |
Output is correct |
24 |
Correct |
4 ms |
1388 KB |
Output is correct |
25 |
Correct |
4 ms |
1388 KB |
Output is correct |
26 |
Correct |
8 ms |
1388 KB |
Output is correct |
27 |
Correct |
8 ms |
1388 KB |
Output is correct |
28 |
Correct |
3 ms |
1388 KB |
Output is correct |
29 |
Correct |
4 ms |
1604 KB |
Output is correct |
30 |
Correct |
3 ms |
1604 KB |
Output is correct |
31 |
Correct |
3 ms |
1604 KB |
Output is correct |
32 |
Correct |
3 ms |
1604 KB |
Output is correct |
33 |
Correct |
7 ms |
1604 KB |
Output is correct |
34 |
Correct |
5 ms |
1604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1604 KB |
Output is correct |
2 |
Correct |
2 ms |
1604 KB |
Output is correct |
3 |
Correct |
2 ms |
1604 KB |
Output is correct |
4 |
Correct |
2 ms |
1604 KB |
Output is correct |
5 |
Correct |
2 ms |
1604 KB |
Output is correct |
6 |
Correct |
2 ms |
1604 KB |
Output is correct |
7 |
Correct |
2 ms |
1604 KB |
Output is correct |
8 |
Correct |
2 ms |
1604 KB |
Output is correct |
9 |
Correct |
8 ms |
1604 KB |
Output is correct |
10 |
Correct |
2 ms |
1604 KB |
Output is correct |
11 |
Correct |
3 ms |
1604 KB |
Output is correct |
12 |
Correct |
3 ms |
1604 KB |
Output is correct |
13 |
Correct |
3 ms |
1604 KB |
Output is correct |
14 |
Correct |
3 ms |
1604 KB |
Output is correct |
15 |
Correct |
3 ms |
1604 KB |
Output is correct |
16 |
Correct |
2 ms |
1604 KB |
Output is correct |
17 |
Correct |
3 ms |
1604 KB |
Output is correct |
18 |
Correct |
2 ms |
1604 KB |
Output is correct |
19 |
Correct |
2 ms |
1604 KB |
Output is correct |
20 |
Correct |
9 ms |
1604 KB |
Output is correct |
21 |
Correct |
3 ms |
1604 KB |
Output is correct |
22 |
Correct |
3 ms |
1604 KB |
Output is correct |
23 |
Correct |
3 ms |
1604 KB |
Output is correct |
24 |
Correct |
6 ms |
1604 KB |
Output is correct |
25 |
Correct |
4 ms |
1604 KB |
Output is correct |
26 |
Correct |
8 ms |
1604 KB |
Output is correct |
27 |
Correct |
9 ms |
1604 KB |
Output is correct |
28 |
Correct |
4 ms |
1604 KB |
Output is correct |
29 |
Correct |
4 ms |
1604 KB |
Output is correct |
30 |
Correct |
3 ms |
1604 KB |
Output is correct |
31 |
Correct |
4 ms |
1604 KB |
Output is correct |
32 |
Correct |
4 ms |
1604 KB |
Output is correct |
33 |
Correct |
5 ms |
1604 KB |
Output is correct |
34 |
Correct |
5 ms |
1604 KB |
Output is correct |
35 |
Correct |
19 ms |
1772 KB |
Output is correct |
36 |
Correct |
6 ms |
1772 KB |
Output is correct |
37 |
Correct |
15 ms |
1772 KB |
Output is correct |
38 |
Correct |
21 ms |
2028 KB |
Output is correct |
39 |
Correct |
22 ms |
2028 KB |
Output is correct |
40 |
Correct |
22 ms |
2028 KB |
Output is correct |
41 |
Correct |
23 ms |
2028 KB |
Output is correct |
42 |
Correct |
99 ms |
2028 KB |
Output is correct |
43 |
Correct |
99 ms |
2028 KB |
Output is correct |
44 |
Correct |
104 ms |
2028 KB |
Output is correct |
45 |
Correct |
20 ms |
2028 KB |
Output is correct |
46 |
Correct |
20 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2028 KB |
Output is correct |
2 |
Correct |
2 ms |
2028 KB |
Output is correct |
3 |
Correct |
2 ms |
2028 KB |
Output is correct |
4 |
Correct |
2 ms |
2028 KB |
Output is correct |
5 |
Correct |
2 ms |
2028 KB |
Output is correct |
6 |
Correct |
2 ms |
2028 KB |
Output is correct |
7 |
Correct |
2 ms |
2028 KB |
Output is correct |
8 |
Correct |
2 ms |
2028 KB |
Output is correct |
9 |
Correct |
2 ms |
2028 KB |
Output is correct |
10 |
Correct |
3 ms |
2028 KB |
Output is correct |
11 |
Correct |
4 ms |
2028 KB |
Output is correct |
12 |
Correct |
3 ms |
2028 KB |
Output is correct |
13 |
Correct |
5 ms |
2028 KB |
Output is correct |
14 |
Correct |
4 ms |
2028 KB |
Output is correct |
15 |
Correct |
4 ms |
2028 KB |
Output is correct |
16 |
Correct |
3 ms |
2028 KB |
Output is correct |
17 |
Correct |
4 ms |
2028 KB |
Output is correct |
18 |
Correct |
4 ms |
2028 KB |
Output is correct |
19 |
Correct |
3 ms |
2028 KB |
Output is correct |
20 |
Correct |
9 ms |
2028 KB |
Output is correct |
21 |
Correct |
3 ms |
2028 KB |
Output is correct |
22 |
Correct |
3 ms |
2028 KB |
Output is correct |
23 |
Correct |
4 ms |
2028 KB |
Output is correct |
24 |
Correct |
4 ms |
2028 KB |
Output is correct |
25 |
Correct |
4 ms |
2028 KB |
Output is correct |
26 |
Correct |
8 ms |
2028 KB |
Output is correct |
27 |
Correct |
7 ms |
2028 KB |
Output is correct |
28 |
Correct |
3 ms |
2028 KB |
Output is correct |
29 |
Correct |
4 ms |
2028 KB |
Output is correct |
30 |
Correct |
3 ms |
2028 KB |
Output is correct |
31 |
Correct |
4 ms |
2028 KB |
Output is correct |
32 |
Correct |
4 ms |
2028 KB |
Output is correct |
33 |
Correct |
7 ms |
2028 KB |
Output is correct |
34 |
Correct |
7 ms |
2028 KB |
Output is correct |
35 |
Correct |
24 ms |
2028 KB |
Output is correct |
36 |
Correct |
5 ms |
2028 KB |
Output is correct |
37 |
Correct |
23 ms |
2028 KB |
Output is correct |
38 |
Correct |
32 ms |
2028 KB |
Output is correct |
39 |
Correct |
23 ms |
2028 KB |
Output is correct |
40 |
Correct |
23 ms |
2028 KB |
Output is correct |
41 |
Correct |
26 ms |
2028 KB |
Output is correct |
42 |
Correct |
92 ms |
2028 KB |
Output is correct |
43 |
Correct |
113 ms |
2028 KB |
Output is correct |
44 |
Correct |
97 ms |
2028 KB |
Output is correct |
45 |
Correct |
25 ms |
2028 KB |
Output is correct |
46 |
Correct |
19 ms |
2028 KB |
Output is correct |
47 |
Correct |
32 ms |
2540 KB |
Output is correct |
48 |
Correct |
19 ms |
2540 KB |
Output is correct |
49 |
Correct |
18 ms |
2540 KB |
Output is correct |
50 |
Correct |
15 ms |
2540 KB |
Output is correct |
51 |
Correct |
47 ms |
4328 KB |
Output is correct |
52 |
Correct |
47 ms |
4328 KB |
Output is correct |
53 |
Correct |
33 ms |
4628 KB |
Output is correct |
54 |
Correct |
4 ms |
4628 KB |
Output is correct |
55 |
Correct |
5 ms |
4628 KB |
Output is correct |
56 |
Execution timed out |
1060 ms |
5056 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |