Submission #533090

# Submission time Handle Problem Language Result Execution time Memory
533090 2022-03-04T17:39:07 Z new_acc Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
292 ms 218468 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=3e4+10;
vector<pair<int,short> > graf[N*20];
pair<short,short>w[N];
int l,num[N];
vector<short> li[300];
bitset<N>bb;
bitset<N*20>vis;
vi kol[1000*1000*4+10];
int n,m;
void single(int x){
	if(li[x].empty()) return;
	for(int i=1;i<=x;i++){
		num[i]=++l;
		graf[l].push_back({i,0});
	}
	for(int i=x+1;i<=n;i++){
		num[i]=++l;
		graf[l].push_back({i,0}),graf[l].push_back({num[i-x],1});
	}
	for(int i=1;i<=n;i++) bb[i]=0;
	for(auto u:li[x]) bb[w[u].fi]=1;
	for(int i=1;i<=n;i++) if(bb[i]) graf[i].push_back({num[i],0});
	for(int i=n;i>=n-x+1;i--){
		num[i]=++l;
		graf[l].push_back({i,0});
	}
	for(int i=n-x;i>=1;i--){
		num[i]=++l;
		graf[l].push_back({i,0}),graf[l].push_back({num[i+x],1});
	}
	for(int i=1;i<=n;i++) if(bb[i]) graf[i].push_back({num[i],0});
}
int Dijkstra(int p,int k){
	kol[0].push_back(p);
	for(int i=0;i<=(int)4e6;i++){
		for(int j=0;j<kol[i].size();j++){
			int v=kol[i][j];
			if(vis[v]) continue;
			vis[v]=1;
			if(v==k) return i;
			for(auto u:graf[v])
				if(!vis[u.fi] and i+u.se<=(int)4e6) kol[i+u.se].push_back(u.fi);
		}
	}
	return -1;
}
void solve(){
	cin>>n>>m;
	l=n;
	int p=sqrt(n)/20;
	for(int i=1;i<=m;i++){
		cin>>w[i].fi>>w[i].se;
		w[i].fi++;
		if(w[i].se>p){
			for(int j=w[i].fi+w[i].se;j<=n;j+=w[i].se) graf[w[i].fi].push_back({j,(j-w[i].fi)/w[i].se});
			for(int j=w[i].fi-w[i].se;j>=1;j-=w[i].se) graf[w[i].fi].push_back({j,(w[i].fi-j)/w[i].se});
		}else li[w[i].se].push_back(i);
	}
	for(int i=1;i<=p;i++) single(i);		
	cout<<Dijkstra(w[1].fi,w[2].fi)<<"\n";
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	solve();
}

Compilation message

skyscraper.cpp: In function 'int Dijkstra(int, int)':
skyscraper.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int j=0;j<kol[i].size();j++){
      |               ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 108232 KB Output is correct
2 Correct 49 ms 108340 KB Output is correct
3 Correct 49 ms 108320 KB Output is correct
4 Correct 60 ms 108352 KB Output is correct
5 Correct 50 ms 108228 KB Output is correct
6 Correct 50 ms 108304 KB Output is correct
7 Correct 49 ms 108228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 108248 KB Output is correct
2 Correct 49 ms 108340 KB Output is correct
3 Correct 50 ms 108336 KB Output is correct
4 Correct 59 ms 108356 KB Output is correct
5 Correct 53 ms 108248 KB Output is correct
6 Correct 49 ms 108228 KB Output is correct
7 Correct 50 ms 108236 KB Output is correct
8 Correct 49 ms 108248 KB Output is correct
9 Correct 51 ms 108284 KB Output is correct
10 Correct 50 ms 108356 KB Output is correct
11 Correct 49 ms 108340 KB Output is correct
12 Correct 61 ms 110548 KB Output is correct
13 Correct 57 ms 110536 KB Output is correct
14 Correct 52 ms 108356 KB Output is correct
15 Correct 49 ms 108340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 108236 KB Output is correct
2 Correct 52 ms 108336 KB Output is correct
3 Correct 51 ms 108288 KB Output is correct
4 Correct 59 ms 108396 KB Output is correct
5 Correct 54 ms 108228 KB Output is correct
6 Correct 51 ms 108228 KB Output is correct
7 Correct 49 ms 108228 KB Output is correct
8 Correct 49 ms 108228 KB Output is correct
9 Correct 52 ms 108332 KB Output is correct
10 Correct 51 ms 108356 KB Output is correct
11 Correct 51 ms 108444 KB Output is correct
12 Correct 55 ms 110528 KB Output is correct
13 Correct 55 ms 110536 KB Output is correct
14 Correct 51 ms 108356 KB Output is correct
15 Correct 51 ms 108392 KB Output is correct
16 Correct 57 ms 108348 KB Output is correct
17 Correct 53 ms 108564 KB Output is correct
18 Correct 57 ms 108440 KB Output is correct
19 Correct 62 ms 108492 KB Output is correct
20 Correct 51 ms 108560 KB Output is correct
21 Correct 57 ms 108292 KB Output is correct
22 Correct 58 ms 108496 KB Output is correct
23 Correct 51 ms 108404 KB Output is correct
24 Correct 51 ms 108548 KB Output is correct
25 Correct 50 ms 108552 KB Output is correct
26 Correct 51 ms 108744 KB Output is correct
27 Correct 54 ms 108692 KB Output is correct
28 Correct 52 ms 108868 KB Output is correct
29 Correct 53 ms 109448 KB Output is correct
30 Correct 50 ms 108740 KB Output is correct
31 Correct 50 ms 108968 KB Output is correct
32 Correct 56 ms 108836 KB Output is correct
33 Correct 54 ms 110312 KB Output is correct
34 Correct 56 ms 110244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 108324 KB Output is correct
2 Correct 50 ms 108228 KB Output is correct
3 Correct 50 ms 108228 KB Output is correct
4 Correct 56 ms 108336 KB Output is correct
5 Correct 51 ms 108364 KB Output is correct
6 Correct 53 ms 108356 KB Output is correct
7 Correct 51 ms 108228 KB Output is correct
8 Correct 50 ms 108336 KB Output is correct
9 Correct 52 ms 108284 KB Output is correct
10 Correct 51 ms 108292 KB Output is correct
11 Correct 50 ms 108416 KB Output is correct
12 Correct 51 ms 110536 KB Output is correct
13 Correct 55 ms 110536 KB Output is correct
14 Correct 53 ms 108344 KB Output is correct
15 Correct 54 ms 108352 KB Output is correct
16 Correct 55 ms 108356 KB Output is correct
17 Correct 50 ms 108556 KB Output is correct
18 Correct 58 ms 108464 KB Output is correct
19 Correct 57 ms 108432 KB Output is correct
20 Correct 53 ms 108612 KB Output is correct
21 Correct 58 ms 108352 KB Output is correct
22 Correct 59 ms 108508 KB Output is correct
23 Correct 51 ms 108440 KB Output is correct
24 Correct 50 ms 108608 KB Output is correct
25 Correct 50 ms 108684 KB Output is correct
26 Correct 53 ms 108780 KB Output is correct
27 Correct 52 ms 108620 KB Output is correct
28 Correct 52 ms 108992 KB Output is correct
29 Correct 55 ms 109412 KB Output is correct
30 Correct 50 ms 108792 KB Output is correct
31 Correct 51 ms 108916 KB Output is correct
32 Correct 51 ms 108684 KB Output is correct
33 Correct 55 ms 110276 KB Output is correct
34 Correct 56 ms 110304 KB Output is correct
35 Correct 60 ms 110288 KB Output is correct
36 Correct 55 ms 108612 KB Output is correct
37 Correct 60 ms 111780 KB Output is correct
38 Correct 62 ms 111452 KB Output is correct
39 Correct 61 ms 111052 KB Output is correct
40 Correct 59 ms 111008 KB Output is correct
41 Correct 62 ms 111348 KB Output is correct
42 Correct 56 ms 109016 KB Output is correct
43 Correct 55 ms 109072 KB Output is correct
44 Correct 55 ms 108988 KB Output is correct
45 Correct 65 ms 115404 KB Output is correct
46 Correct 64 ms 115244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 108236 KB Output is correct
2 Correct 50 ms 108276 KB Output is correct
3 Correct 51 ms 108236 KB Output is correct
4 Correct 59 ms 108228 KB Output is correct
5 Correct 50 ms 108224 KB Output is correct
6 Correct 50 ms 108312 KB Output is correct
7 Correct 53 ms 108228 KB Output is correct
8 Correct 50 ms 108220 KB Output is correct
9 Correct 51 ms 108272 KB Output is correct
10 Correct 50 ms 108364 KB Output is correct
11 Correct 49 ms 108356 KB Output is correct
12 Correct 53 ms 110512 KB Output is correct
13 Correct 54 ms 110504 KB Output is correct
14 Correct 50 ms 108316 KB Output is correct
15 Correct 49 ms 108356 KB Output is correct
16 Correct 58 ms 108412 KB Output is correct
17 Correct 53 ms 108624 KB Output is correct
18 Correct 59 ms 108504 KB Output is correct
19 Correct 58 ms 108484 KB Output is correct
20 Correct 51 ms 108588 KB Output is correct
21 Correct 57 ms 108248 KB Output is correct
22 Correct 56 ms 108488 KB Output is correct
23 Correct 50 ms 108388 KB Output is correct
24 Correct 54 ms 108612 KB Output is correct
25 Correct 51 ms 108612 KB Output is correct
26 Correct 55 ms 108744 KB Output is correct
27 Correct 54 ms 108704 KB Output is correct
28 Correct 52 ms 108868 KB Output is correct
29 Correct 54 ms 109316 KB Output is correct
30 Correct 52 ms 108728 KB Output is correct
31 Correct 51 ms 108868 KB Output is correct
32 Correct 52 ms 108704 KB Output is correct
33 Correct 55 ms 110300 KB Output is correct
34 Correct 55 ms 110252 KB Output is correct
35 Correct 71 ms 110288 KB Output is correct
36 Correct 50 ms 108596 KB Output is correct
37 Correct 58 ms 111724 KB Output is correct
38 Correct 61 ms 111420 KB Output is correct
39 Correct 59 ms 110940 KB Output is correct
40 Correct 59 ms 111044 KB Output is correct
41 Correct 69 ms 111276 KB Output is correct
42 Correct 57 ms 109128 KB Output is correct
43 Correct 55 ms 108996 KB Output is correct
44 Correct 54 ms 108988 KB Output is correct
45 Correct 67 ms 115304 KB Output is correct
46 Correct 66 ms 115248 KB Output is correct
47 Correct 93 ms 122068 KB Output is correct
48 Correct 87 ms 117956 KB Output is correct
49 Correct 73 ms 113224 KB Output is correct
50 Correct 71 ms 113476 KB Output is correct
51 Correct 93 ms 123052 KB Output is correct
52 Correct 96 ms 123376 KB Output is correct
53 Correct 82 ms 114572 KB Output is correct
54 Correct 63 ms 110796 KB Output is correct
55 Correct 76 ms 114900 KB Output is correct
56 Correct 68 ms 112564 KB Output is correct
57 Correct 110 ms 141588 KB Output is correct
58 Correct 75 ms 116208 KB Output is correct
59 Correct 93 ms 120232 KB Output is correct
60 Correct 90 ms 120728 KB Output is correct
61 Correct 87 ms 119868 KB Output is correct
62 Correct 105 ms 128928 KB Output is correct
63 Correct 111 ms 137740 KB Output is correct
64 Correct 125 ms 144092 KB Output is correct
65 Correct 155 ms 160152 KB Output is correct
66 Correct 292 ms 218468 KB Output is correct
67 Correct 285 ms 217528 KB Output is correct