#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
const int nmax=30005;
const int buck=200;
vector<int> v[nmax],mare[nmax];
bool E[nmax];
int d[nmax][buck+5];
int n,m,i,j,wh,x,cost,use,fin,k,val,md;
struct node
{
int fi,se,cat;
};
struct cmp
{
bool operator() (node unu,node doi)
{
return unu.cat>doi.cat;
}
};
priority_queue< node,vector<node>, cmp > pq;
void prp(int a,int b,int dist)
{
if(dist<d[a][b])
{
d[a][b]=dist;
pq.push({a,b,d[a][b]});
}
}
int abss(int x)
{
if(x<0) return -x;
return x;
}
int dij()
{
while(!pq.empty())
{
i=pq.top().fi;
j=pq.top().se;
cost=pq.top().cat;
pq.pop();
if(cost==d[i][j])
{
if(i==fin)
return cost;
if(i-j>=0) prp(i-j,j,cost+1);
if(i+j<n) prp(i+j,j,cost+1);
for(k=0; k<v[i].size(); k++)
prp(i,v[i][k],cost);
if(!E[i])
{
E[i]=1;
for(k=0; k<mare[i].size(); k++)
{
val=mare[i][k];
md=i%val;
for(j=md; j<n; j+=val)
prp(j,0,cost+abss(j-i)/val);
}
}
}
}
return -1;
}
int main()
{
// freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<=buck;j++)
d[i][j]=INT_MAX;
for(i=0;i<m;i++)
{
cin>>wh>>x;
if(x<=buck) v[wh].push_back(x);
else mare[wh].push_back(x);
if(i==0)
pq.push({wh,0,0}),d[wh][0]=0;
if(i==1)
fin=wh;
}
cout<<dij();
return 0;
}
Compilation message
skyscraper.cpp: In function 'int dij()':
skyscraper.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=0; k<v[i].size(); k++)
~^~~~~~~~~~~~
skyscraper.cpp:57:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=0; k<mare[i].size(); k++)
~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1784 KB |
Output is correct |
2 |
Correct |
3 ms |
1916 KB |
Output is correct |
3 |
Correct |
3 ms |
1916 KB |
Output is correct |
4 |
Correct |
3 ms |
1916 KB |
Output is correct |
5 |
Correct |
3 ms |
1916 KB |
Output is correct |
6 |
Correct |
3 ms |
1916 KB |
Output is correct |
7 |
Correct |
3 ms |
1916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1916 KB |
Output is correct |
2 |
Correct |
3 ms |
1916 KB |
Output is correct |
3 |
Correct |
3 ms |
1916 KB |
Output is correct |
4 |
Correct |
3 ms |
1916 KB |
Output is correct |
5 |
Correct |
3 ms |
1984 KB |
Output is correct |
6 |
Correct |
3 ms |
1984 KB |
Output is correct |
7 |
Correct |
3 ms |
2000 KB |
Output is correct |
8 |
Correct |
3 ms |
2000 KB |
Output is correct |
9 |
Correct |
3 ms |
2128 KB |
Output is correct |
10 |
Correct |
3 ms |
2140 KB |
Output is correct |
11 |
Correct |
3 ms |
2156 KB |
Output is correct |
12 |
Correct |
3 ms |
2156 KB |
Output is correct |
13 |
Correct |
3 ms |
2156 KB |
Output is correct |
14 |
Correct |
4 ms |
2172 KB |
Output is correct |
15 |
Correct |
4 ms |
2172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2172 KB |
Output is correct |
2 |
Correct |
3 ms |
2172 KB |
Output is correct |
3 |
Correct |
3 ms |
2172 KB |
Output is correct |
4 |
Correct |
3 ms |
2172 KB |
Output is correct |
5 |
Correct |
3 ms |
2172 KB |
Output is correct |
6 |
Correct |
3 ms |
2172 KB |
Output is correct |
7 |
Correct |
3 ms |
2172 KB |
Output is correct |
8 |
Correct |
3 ms |
2172 KB |
Output is correct |
9 |
Correct |
3 ms |
2172 KB |
Output is correct |
10 |
Correct |
3 ms |
2172 KB |
Output is correct |
11 |
Correct |
3 ms |
2172 KB |
Output is correct |
12 |
Correct |
3 ms |
2172 KB |
Output is correct |
13 |
Correct |
3 ms |
2172 KB |
Output is correct |
14 |
Correct |
4 ms |
2172 KB |
Output is correct |
15 |
Correct |
4 ms |
2172 KB |
Output is correct |
16 |
Correct |
3 ms |
2172 KB |
Output is correct |
17 |
Correct |
4 ms |
2684 KB |
Output is correct |
18 |
Correct |
4 ms |
3452 KB |
Output is correct |
19 |
Correct |
4 ms |
3592 KB |
Output is correct |
20 |
Correct |
5 ms |
3728 KB |
Output is correct |
21 |
Correct |
3 ms |
3728 KB |
Output is correct |
22 |
Correct |
4 ms |
3728 KB |
Output is correct |
23 |
Correct |
4 ms |
3728 KB |
Output is correct |
24 |
Correct |
5 ms |
3728 KB |
Output is correct |
25 |
Correct |
4 ms |
3796 KB |
Output is correct |
26 |
Correct |
4 ms |
3796 KB |
Output is correct |
27 |
Correct |
4 ms |
3832 KB |
Output is correct |
28 |
Correct |
5 ms |
3848 KB |
Output is correct |
29 |
Correct |
8 ms |
3868 KB |
Output is correct |
30 |
Correct |
5 ms |
3868 KB |
Output is correct |
31 |
Correct |
6 ms |
3868 KB |
Output is correct |
32 |
Correct |
5 ms |
3868 KB |
Output is correct |
33 |
Correct |
12 ms |
3888 KB |
Output is correct |
34 |
Correct |
9 ms |
3900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3900 KB |
Output is correct |
2 |
Correct |
3 ms |
3900 KB |
Output is correct |
3 |
Correct |
3 ms |
3900 KB |
Output is correct |
4 |
Correct |
3 ms |
3900 KB |
Output is correct |
5 |
Correct |
3 ms |
3900 KB |
Output is correct |
6 |
Correct |
3 ms |
3900 KB |
Output is correct |
7 |
Correct |
3 ms |
3900 KB |
Output is correct |
8 |
Correct |
8 ms |
3900 KB |
Output is correct |
9 |
Correct |
3 ms |
3900 KB |
Output is correct |
10 |
Correct |
3 ms |
3900 KB |
Output is correct |
11 |
Correct |
3 ms |
3900 KB |
Output is correct |
12 |
Correct |
3 ms |
3900 KB |
Output is correct |
13 |
Correct |
3 ms |
3900 KB |
Output is correct |
14 |
Correct |
4 ms |
3900 KB |
Output is correct |
15 |
Correct |
4 ms |
3900 KB |
Output is correct |
16 |
Correct |
3 ms |
3900 KB |
Output is correct |
17 |
Correct |
4 ms |
3900 KB |
Output is correct |
18 |
Correct |
4 ms |
3900 KB |
Output is correct |
19 |
Correct |
4 ms |
3900 KB |
Output is correct |
20 |
Correct |
5 ms |
3936 KB |
Output is correct |
21 |
Correct |
3 ms |
3936 KB |
Output is correct |
22 |
Correct |
4 ms |
3936 KB |
Output is correct |
23 |
Correct |
5 ms |
3936 KB |
Output is correct |
24 |
Correct |
5 ms |
3936 KB |
Output is correct |
25 |
Correct |
5 ms |
4000 KB |
Output is correct |
26 |
Correct |
5 ms |
4020 KB |
Output is correct |
27 |
Correct |
5 ms |
4036 KB |
Output is correct |
28 |
Correct |
6 ms |
4048 KB |
Output is correct |
29 |
Correct |
8 ms |
4200 KB |
Output is correct |
30 |
Correct |
5 ms |
4200 KB |
Output is correct |
31 |
Correct |
7 ms |
4200 KB |
Output is correct |
32 |
Correct |
6 ms |
4200 KB |
Output is correct |
33 |
Correct |
13 ms |
4200 KB |
Output is correct |
34 |
Correct |
9 ms |
4200 KB |
Output is correct |
35 |
Correct |
11 ms |
4200 KB |
Output is correct |
36 |
Correct |
5 ms |
4200 KB |
Output is correct |
37 |
Correct |
9 ms |
4764 KB |
Output is correct |
38 |
Correct |
11 ms |
5048 KB |
Output is correct |
39 |
Correct |
11 ms |
5184 KB |
Output is correct |
40 |
Correct |
11 ms |
5576 KB |
Output is correct |
41 |
Correct |
12 ms |
5844 KB |
Output is correct |
42 |
Correct |
9 ms |
6104 KB |
Output is correct |
43 |
Correct |
9 ms |
6184 KB |
Output is correct |
44 |
Correct |
10 ms |
6392 KB |
Output is correct |
45 |
Correct |
54 ms |
7052 KB |
Output is correct |
46 |
Correct |
36 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7260 KB |
Output is correct |
2 |
Correct |
3 ms |
7260 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7260 KB |
Output is correct |
5 |
Correct |
3 ms |
7260 KB |
Output is correct |
6 |
Correct |
3 ms |
7260 KB |
Output is correct |
7 |
Correct |
3 ms |
7260 KB |
Output is correct |
8 |
Correct |
3 ms |
7260 KB |
Output is correct |
9 |
Correct |
3 ms |
7260 KB |
Output is correct |
10 |
Correct |
3 ms |
7260 KB |
Output is correct |
11 |
Correct |
3 ms |
7260 KB |
Output is correct |
12 |
Correct |
3 ms |
7260 KB |
Output is correct |
13 |
Correct |
3 ms |
7260 KB |
Output is correct |
14 |
Correct |
4 ms |
7260 KB |
Output is correct |
15 |
Correct |
4 ms |
7260 KB |
Output is correct |
16 |
Correct |
3 ms |
7260 KB |
Output is correct |
17 |
Correct |
4 ms |
7260 KB |
Output is correct |
18 |
Correct |
4 ms |
7260 KB |
Output is correct |
19 |
Correct |
4 ms |
7260 KB |
Output is correct |
20 |
Correct |
5 ms |
7260 KB |
Output is correct |
21 |
Correct |
4 ms |
7260 KB |
Output is correct |
22 |
Correct |
4 ms |
7260 KB |
Output is correct |
23 |
Correct |
5 ms |
7260 KB |
Output is correct |
24 |
Correct |
6 ms |
7260 KB |
Output is correct |
25 |
Correct |
5 ms |
7260 KB |
Output is correct |
26 |
Correct |
5 ms |
7260 KB |
Output is correct |
27 |
Correct |
5 ms |
7260 KB |
Output is correct |
28 |
Correct |
5 ms |
7260 KB |
Output is correct |
29 |
Correct |
7 ms |
7260 KB |
Output is correct |
30 |
Correct |
4 ms |
7260 KB |
Output is correct |
31 |
Correct |
6 ms |
7260 KB |
Output is correct |
32 |
Correct |
5 ms |
7260 KB |
Output is correct |
33 |
Correct |
12 ms |
7260 KB |
Output is correct |
34 |
Correct |
9 ms |
7260 KB |
Output is correct |
35 |
Correct |
10 ms |
7260 KB |
Output is correct |
36 |
Correct |
4 ms |
7260 KB |
Output is correct |
37 |
Correct |
9 ms |
7488 KB |
Output is correct |
38 |
Correct |
11 ms |
7780 KB |
Output is correct |
39 |
Correct |
10 ms |
7912 KB |
Output is correct |
40 |
Correct |
10 ms |
7912 KB |
Output is correct |
41 |
Correct |
12 ms |
7992 KB |
Output is correct |
42 |
Correct |
8 ms |
7992 KB |
Output is correct |
43 |
Correct |
9 ms |
7992 KB |
Output is correct |
44 |
Correct |
8 ms |
7992 KB |
Output is correct |
45 |
Correct |
52 ms |
8308 KB |
Output is correct |
46 |
Correct |
54 ms |
8456 KB |
Output is correct |
47 |
Correct |
19 ms |
17140 KB |
Output is correct |
48 |
Correct |
22 ms |
25556 KB |
Output is correct |
49 |
Correct |
27 ms |
27608 KB |
Output is correct |
50 |
Correct |
23 ms |
29712 KB |
Output is correct |
51 |
Correct |
36 ms |
32476 KB |
Output is correct |
52 |
Correct |
45 ms |
32852 KB |
Output is correct |
53 |
Correct |
29 ms |
32852 KB |
Output is correct |
54 |
Correct |
25 ms |
32852 KB |
Output is correct |
55 |
Correct |
22 ms |
32852 KB |
Output is correct |
56 |
Correct |
30 ms |
33268 KB |
Output is correct |
57 |
Correct |
20 ms |
33268 KB |
Output is correct |
58 |
Correct |
31 ms |
33268 KB |
Output is correct |
59 |
Correct |
30 ms |
33268 KB |
Output is correct |
60 |
Correct |
30 ms |
33268 KB |
Output is correct |
61 |
Correct |
30 ms |
33440 KB |
Output is correct |
62 |
Correct |
63 ms |
34532 KB |
Output is correct |
63 |
Correct |
61 ms |
35672 KB |
Output is correct |
64 |
Correct |
66 ms |
35812 KB |
Output is correct |
65 |
Correct |
278 ms |
36004 KB |
Output is correct |
66 |
Correct |
683 ms |
36232 KB |
Output is correct |
67 |
Correct |
458 ms |
36440 KB |
Output is correct |