#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=30005,INF=2e9;
int b[MAXN],p[MAXN],dist[MAXN];
vector<pii> adj[MAXN];
vector<int> doge[MAXN];
bitset<MAXN> sudah,ada[MAXN];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++){
cin >> b[i] >> p[i];
doge[b[i]].push_back(p[i]);
}
for(int i=0;i<n;i++){
sort(doge[i].begin(),doge[i].end());
doge[i].erase(unique(doge[i].begin(),doge[i].end()),doge[i].end());
reverse(doge[i].begin(),doge[i].end());
for(auto isi : doge[i])ada[i][isi]=true;
}
for(int i=0;i<n;i++){
sudah.reset();
for(auto isi : doge[i]){
for(int j=1;j*isi+i<n;j++){
if(sudah[j*isi+i])continue;
adj[i].push_back({j*isi+i,j});
sudah[j*isi+i]=true;
if(ada[j*isi+i][isi])break;
}
for(int j=1;i-j*isi>=0;j++){
if(sudah[i-j*isi])continue;
adj[i].push_back({i-j*isi,j});
sudah[i-j*isi]-true;
if(ada[i-j*isi][isi])break;
}
}
dist[i]=INF;
}
//total edgenya jadi N*sqrt(N) kayanya
priority_queue<pii,vector<pii>,greater<pii> > PQ;
dist[b[1]]=0;
PQ.push({0,b[1]});
while(!PQ.empty()){
pii now=PQ.top();
PQ.pop();
if(dist[now.second]<now.first)continue;
for(auto nxt : adj[now.second]){
if(dist[now.second]+nxt.second<dist[nxt.first]){
dist[nxt.first]=dist[now.second]+nxt.second;
PQ.push({dist[nxt.first],nxt.first});
}
}
}
if(dist[b[2]]==INF)dist[b[2]]=-1;
cout << dist[b[2]] << '\n';
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:19: warning: value computed is not used [-Wunused-value]
sudah[i-j*isi]-true;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1792 KB |
Output is correct |
2 |
Correct |
1 ms |
1792 KB |
Output is correct |
3 |
Correct |
1 ms |
1792 KB |
Output is correct |
4 |
Correct |
1 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
1920 KB |
Output is correct |
6 |
Correct |
2 ms |
1792 KB |
Output is correct |
7 |
Correct |
2 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1792 KB |
Output is correct |
2 |
Correct |
2 ms |
1792 KB |
Output is correct |
3 |
Correct |
1 ms |
1792 KB |
Output is correct |
4 |
Correct |
1 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1792 KB |
Output is correct |
7 |
Correct |
1 ms |
1792 KB |
Output is correct |
8 |
Correct |
1 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
1 ms |
2176 KB |
Output is correct |
11 |
Correct |
2 ms |
2176 KB |
Output is correct |
12 |
Correct |
1 ms |
1792 KB |
Output is correct |
13 |
Correct |
2 ms |
2176 KB |
Output is correct |
14 |
Correct |
2 ms |
2048 KB |
Output is correct |
15 |
Correct |
2 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1792 KB |
Output is correct |
2 |
Correct |
1 ms |
1792 KB |
Output is correct |
3 |
Correct |
1 ms |
1792 KB |
Output is correct |
4 |
Correct |
1 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1792 KB |
Output is correct |
7 |
Correct |
2 ms |
1792 KB |
Output is correct |
8 |
Correct |
1 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
2 ms |
2176 KB |
Output is correct |
11 |
Correct |
2 ms |
2176 KB |
Output is correct |
12 |
Correct |
1 ms |
1792 KB |
Output is correct |
13 |
Correct |
2 ms |
2176 KB |
Output is correct |
14 |
Correct |
2 ms |
2048 KB |
Output is correct |
15 |
Correct |
3 ms |
2048 KB |
Output is correct |
16 |
Correct |
2 ms |
2560 KB |
Output is correct |
17 |
Correct |
4 ms |
4608 KB |
Output is correct |
18 |
Correct |
4 ms |
4864 KB |
Output is correct |
19 |
Correct |
4 ms |
3712 KB |
Output is correct |
20 |
Correct |
5 ms |
9216 KB |
Output is correct |
21 |
Correct |
2 ms |
3200 KB |
Output is correct |
22 |
Correct |
3 ms |
4224 KB |
Output is correct |
23 |
Correct |
4 ms |
4736 KB |
Output is correct |
24 |
Correct |
5 ms |
6528 KB |
Output is correct |
25 |
Correct |
7 ms |
6784 KB |
Output is correct |
26 |
Correct |
4 ms |
2176 KB |
Output is correct |
27 |
Correct |
3 ms |
2048 KB |
Output is correct |
28 |
Correct |
6 ms |
9472 KB |
Output is correct |
29 |
Correct |
5 ms |
2432 KB |
Output is correct |
30 |
Correct |
4 ms |
2176 KB |
Output is correct |
31 |
Correct |
4 ms |
2432 KB |
Output is correct |
32 |
Correct |
4 ms |
2304 KB |
Output is correct |
33 |
Correct |
5 ms |
2688 KB |
Output is correct |
34 |
Correct |
5 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1792 KB |
Output is correct |
2 |
Correct |
1 ms |
1792 KB |
Output is correct |
3 |
Correct |
1 ms |
1792 KB |
Output is correct |
4 |
Correct |
1 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1792 KB |
Output is correct |
7 |
Correct |
1 ms |
1792 KB |
Output is correct |
8 |
Correct |
1 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
1 ms |
2176 KB |
Output is correct |
11 |
Correct |
2 ms |
2176 KB |
Output is correct |
12 |
Correct |
2 ms |
1792 KB |
Output is correct |
13 |
Correct |
2 ms |
2176 KB |
Output is correct |
14 |
Correct |
2 ms |
2048 KB |
Output is correct |
15 |
Correct |
2 ms |
2048 KB |
Output is correct |
16 |
Correct |
2 ms |
2560 KB |
Output is correct |
17 |
Correct |
3 ms |
4608 KB |
Output is correct |
18 |
Correct |
4 ms |
4864 KB |
Output is correct |
19 |
Correct |
3 ms |
3840 KB |
Output is correct |
20 |
Correct |
6 ms |
9216 KB |
Output is correct |
21 |
Correct |
3 ms |
3200 KB |
Output is correct |
22 |
Correct |
3 ms |
4224 KB |
Output is correct |
23 |
Correct |
4 ms |
4736 KB |
Output is correct |
24 |
Correct |
5 ms |
6528 KB |
Output is correct |
25 |
Correct |
5 ms |
6784 KB |
Output is correct |
26 |
Correct |
3 ms |
2176 KB |
Output is correct |
27 |
Correct |
3 ms |
2176 KB |
Output is correct |
28 |
Correct |
6 ms |
9472 KB |
Output is correct |
29 |
Correct |
5 ms |
2432 KB |
Output is correct |
30 |
Correct |
4 ms |
2176 KB |
Output is correct |
31 |
Correct |
4 ms |
2432 KB |
Output is correct |
32 |
Correct |
4 ms |
2304 KB |
Output is correct |
33 |
Correct |
5 ms |
2688 KB |
Output is correct |
34 |
Correct |
5 ms |
2688 KB |
Output is correct |
35 |
Correct |
12 ms |
8704 KB |
Output is correct |
36 |
Correct |
5 ms |
6016 KB |
Output is correct |
37 |
Correct |
14 ms |
11392 KB |
Output is correct |
38 |
Correct |
17 ms |
11520 KB |
Output is correct |
39 |
Correct |
17 ms |
11648 KB |
Output is correct |
40 |
Correct |
17 ms |
11648 KB |
Output is correct |
41 |
Correct |
17 ms |
11648 KB |
Output is correct |
42 |
Correct |
9 ms |
2816 KB |
Output is correct |
43 |
Correct |
9 ms |
2816 KB |
Output is correct |
44 |
Correct |
10 ms |
9728 KB |
Output is correct |
45 |
Correct |
16 ms |
5596 KB |
Output is correct |
46 |
Correct |
15 ms |
5624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1792 KB |
Output is correct |
2 |
Correct |
1 ms |
1792 KB |
Output is correct |
3 |
Correct |
1 ms |
1792 KB |
Output is correct |
4 |
Correct |
1 ms |
1792 KB |
Output is correct |
5 |
Correct |
2 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1792 KB |
Output is correct |
7 |
Correct |
1 ms |
1792 KB |
Output is correct |
8 |
Correct |
2 ms |
1792 KB |
Output is correct |
9 |
Correct |
2 ms |
1920 KB |
Output is correct |
10 |
Correct |
2 ms |
2176 KB |
Output is correct |
11 |
Correct |
2 ms |
2176 KB |
Output is correct |
12 |
Correct |
2 ms |
1792 KB |
Output is correct |
13 |
Correct |
2 ms |
2176 KB |
Output is correct |
14 |
Correct |
2 ms |
2048 KB |
Output is correct |
15 |
Correct |
2 ms |
2048 KB |
Output is correct |
16 |
Correct |
2 ms |
2560 KB |
Output is correct |
17 |
Correct |
3 ms |
4608 KB |
Output is correct |
18 |
Correct |
4 ms |
4864 KB |
Output is correct |
19 |
Correct |
3 ms |
3840 KB |
Output is correct |
20 |
Correct |
5 ms |
9216 KB |
Output is correct |
21 |
Correct |
2 ms |
3200 KB |
Output is correct |
22 |
Correct |
3 ms |
4224 KB |
Output is correct |
23 |
Correct |
4 ms |
4736 KB |
Output is correct |
24 |
Correct |
5 ms |
6528 KB |
Output is correct |
25 |
Correct |
5 ms |
6784 KB |
Output is correct |
26 |
Correct |
3 ms |
2176 KB |
Output is correct |
27 |
Correct |
3 ms |
2048 KB |
Output is correct |
28 |
Correct |
6 ms |
9472 KB |
Output is correct |
29 |
Correct |
7 ms |
2424 KB |
Output is correct |
30 |
Correct |
4 ms |
2176 KB |
Output is correct |
31 |
Correct |
4 ms |
2432 KB |
Output is correct |
32 |
Correct |
4 ms |
2304 KB |
Output is correct |
33 |
Correct |
6 ms |
2688 KB |
Output is correct |
34 |
Correct |
5 ms |
2688 KB |
Output is correct |
35 |
Correct |
13 ms |
8704 KB |
Output is correct |
36 |
Correct |
5 ms |
6016 KB |
Output is correct |
37 |
Correct |
15 ms |
11392 KB |
Output is correct |
38 |
Correct |
19 ms |
11648 KB |
Output is correct |
39 |
Correct |
17 ms |
11648 KB |
Output is correct |
40 |
Correct |
17 ms |
11648 KB |
Output is correct |
41 |
Correct |
16 ms |
11648 KB |
Output is correct |
42 |
Correct |
8 ms |
2816 KB |
Output is correct |
43 |
Correct |
8 ms |
2688 KB |
Output is correct |
44 |
Correct |
10 ms |
9728 KB |
Output is correct |
45 |
Correct |
15 ms |
5504 KB |
Output is correct |
46 |
Correct |
17 ms |
5632 KB |
Output is correct |
47 |
Correct |
59 ms |
51444 KB |
Output is correct |
48 |
Correct |
49 ms |
60532 KB |
Output is correct |
49 |
Correct |
49 ms |
59896 KB |
Output is correct |
50 |
Correct |
43 ms |
49236 KB |
Output is correct |
51 |
Correct |
83 ms |
79988 KB |
Output is correct |
52 |
Correct |
84 ms |
80576 KB |
Output is correct |
53 |
Correct |
61 ms |
77300 KB |
Output is correct |
54 |
Correct |
25 ms |
2560 KB |
Output is correct |
55 |
Correct |
27 ms |
3060 KB |
Output is correct |
56 |
Correct |
59 ms |
114296 KB |
Output is correct |
57 |
Correct |
63 ms |
20008 KB |
Output is correct |
58 |
Correct |
31 ms |
3572 KB |
Output is correct |
59 |
Correct |
34 ms |
4212 KB |
Output is correct |
60 |
Correct |
35 ms |
5620 KB |
Output is correct |
61 |
Correct |
36 ms |
5496 KB |
Output is correct |
62 |
Correct |
84 ms |
117876 KB |
Output is correct |
63 |
Correct |
94 ms |
23408 KB |
Output is correct |
64 |
Correct |
112 ms |
24696 KB |
Output is correct |
65 |
Correct |
110 ms |
26224 KB |
Output is correct |
66 |
Correct |
118 ms |
26860 KB |
Output is correct |
67 |
Correct |
119 ms |
26988 KB |
Output is correct |