Submission #233338

# Submission time Handle Problem Language Result Execution time Memory
233338 2020-05-20T09:16:05 Z kshitij_sodani Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
196 ms 110552 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n,m;
int aa,bb;
const int ss=3;
vector<pair<pair<int,int>,int>> adj[30001][ss];//((index,power),dist)
int dist[30001][ss];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	int st;
	int endd;
	memset(dist,-1,sizeof(dist));
	for(int j=0;j<m;j++){
		cin>>aa>>bb;
		if(j==0){
			st=aa;
		}
		if(j==1){
			endd=aa;
		}
		if(bb>=ss){
			for(int i=aa+bb;i<n;i+=bb){
				adj[aa][0].pb({{i,0},(i-aa)/bb});
			}
			for(int i=aa-bb;i>=0;i-=bb){
				adj[aa][0].pb({{i,0},(aa-i)/bb});
			}
		}
		else{
			adj[aa][0].pb({{aa,bb},0});
		//	adj[aa][bb].pb({{aa,0},0});
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=1;j<ss;j++){
			if(i+j<n){
				adj[i][j].pb({{i+j,j},1});
			}
			if(i-j>=0 and i-j<n){
				adj[i][j].pb({{i-j,j},1});
			}
			adj[i][j].pb({{i,0},0});

		}
	}*/
	priority_queue<pair<int,pair<int,int>>> ac;
	ac.push({0,{st,0}});
	dist[st][0]=0;
	while(ac.size()){
		pair<int,pair<int,int>> no=ac.top();
		ac.pop();
		no.a=-no.a;
		if(dist[no.b.a][no.b.b]<no.a){
			continue;
		}
	//	cout<<no.b.a<<","<<no.b.b<<","<<no.a<<endl;
		for(auto j:adj[no.b.a][no.b.b]){
			if(dist[j.a.a][j.a.b]==-1 or dist[j.a.a][j.a.b]>dist[no.b.a][no.b.b]+j.b){
				dist[j.a.a][j.a.b]=dist[no.b.a][no.b.b]+j.b;
				ac.push({-dist[j.a.a][j.a.b],{j.a}});
			}
		}
		if(no.b.b>0){
			if(no.b.a+no.b.b<n){
				if(dist[no.b.a+no.b.b][no.b.b]==-1 or dist[no.b.a+no.b.b][no.b.b]>dist[no.b.a][no.b.b]+1){
					dist[no.b.a+no.b.b][no.b.b]=dist[no.b.a][no.b.b]+1;
					ac.push({-dist[no.b.a+no.b.b][no.b.b],{no.b.a+no.b.b,no.b.b}});
				}
			}
			if(no.b.a-no.b.b>=0){
				if(dist[no.b.a-no.b.b][no.b.b]==-1 or dist[no.b.a-no.b.b][no.b.b]>dist[no.b.a][no.b.b]+1){
					dist[no.b.a-no.b.b][no.b.b]=dist[no.b.a][no.b.b]+1;
					ac.push({-dist[no.b.a-no.b.b][no.b.b],{no.b.a-no.b.b,no.b.b}});
				}
			}
			if(dist[no.b.a][0]==-1 or dist[no.b.a][0]>dist[no.b.a][no.b.b]){
				dist[no.b.a][0]=dist[no.b.a][no.b.b];
				ac.push({-dist[no.b.a][0],{no.b.a,0}});
			}
		}


	}
	cout<<dist[endd][0]<<endl;








	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:56:13: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
  dist[st][0]=0;
  ~~~~~~~~~~~^~
skyscraper.cpp:92:20: warning: 'endd' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout<<dist[endd][0]<<endl;
                    ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 7 ms 2816 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 6 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 7 ms 2944 KB Output is correct
12 Correct 6 ms 2816 KB Output is correct
13 Correct 6 ms 2816 KB Output is correct
14 Correct 6 ms 2944 KB Output is correct
15 Correct 6 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 7 ms 2816 KB Output is correct
8 Correct 6 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 6 ms 2816 KB Output is correct
13 Correct 6 ms 2816 KB Output is correct
14 Correct 6 ms 2816 KB Output is correct
15 Correct 6 ms 2816 KB Output is correct
16 Correct 6 ms 2976 KB Output is correct
17 Correct 7 ms 3072 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 6 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 6 ms 2944 KB Output is correct
24 Correct 8 ms 3072 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 2944 KB Output is correct
27 Correct 6 ms 2944 KB Output is correct
28 Correct 7 ms 3072 KB Output is correct
29 Correct 8 ms 3840 KB Output is correct
30 Correct 7 ms 3200 KB Output is correct
31 Correct 7 ms 3328 KB Output is correct
32 Correct 7 ms 3200 KB Output is correct
33 Correct 12 ms 4736 KB Output is correct
34 Correct 10 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 6 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 6 ms 2816 KB Output is correct
13 Correct 6 ms 2864 KB Output is correct
14 Correct 6 ms 2816 KB Output is correct
15 Correct 6 ms 2944 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 8 ms 3072 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 7 ms 2944 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 6 ms 2944 KB Output is correct
24 Correct 8 ms 3072 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 3072 KB Output is correct
27 Correct 6 ms 2944 KB Output is correct
28 Correct 7 ms 3072 KB Output is correct
29 Correct 8 ms 3968 KB Output is correct
30 Correct 7 ms 3200 KB Output is correct
31 Correct 7 ms 3328 KB Output is correct
32 Correct 7 ms 3200 KB Output is correct
33 Correct 10 ms 4864 KB Output is correct
34 Correct 10 ms 4736 KB Output is correct
35 Correct 15 ms 4608 KB Output is correct
36 Correct 8 ms 3072 KB Output is correct
37 Correct 18 ms 6912 KB Output is correct
38 Correct 18 ms 6144 KB Output is correct
39 Correct 18 ms 6144 KB Output is correct
40 Correct 18 ms 6144 KB Output is correct
41 Correct 25 ms 5880 KB Output is correct
42 Correct 11 ms 3520 KB Output is correct
43 Correct 12 ms 3392 KB Output is correct
44 Correct 12 ms 3344 KB Output is correct
45 Correct 21 ms 9984 KB Output is correct
46 Correct 21 ms 9984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 6 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 7 ms 2944 KB Output is correct
12 Correct 6 ms 2944 KB Output is correct
13 Correct 7 ms 2816 KB Output is correct
14 Correct 7 ms 2816 KB Output is correct
15 Correct 6 ms 2816 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 7 ms 3072 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 7 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 7 ms 2944 KB Output is correct
24 Correct 8 ms 3072 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 2944 KB Output is correct
27 Correct 7 ms 2944 KB Output is correct
28 Correct 7 ms 3072 KB Output is correct
29 Correct 8 ms 3968 KB Output is correct
30 Correct 7 ms 3200 KB Output is correct
31 Correct 7 ms 3328 KB Output is correct
32 Correct 7 ms 3200 KB Output is correct
33 Correct 10 ms 4736 KB Output is correct
34 Correct 10 ms 4736 KB Output is correct
35 Correct 15 ms 4608 KB Output is correct
36 Correct 8 ms 3072 KB Output is correct
37 Correct 17 ms 6912 KB Output is correct
38 Correct 18 ms 6144 KB Output is correct
39 Correct 20 ms 6272 KB Output is correct
40 Correct 19 ms 6144 KB Output is correct
41 Correct 18 ms 5888 KB Output is correct
42 Correct 12 ms 3520 KB Output is correct
43 Correct 11 ms 3452 KB Output is correct
44 Correct 11 ms 3412 KB Output is correct
45 Correct 21 ms 9984 KB Output is correct
46 Correct 21 ms 9984 KB Output is correct
47 Correct 50 ms 17400 KB Output is correct
48 Correct 17 ms 5888 KB Output is correct
49 Correct 16 ms 4992 KB Output is correct
50 Correct 13 ms 4736 KB Output is correct
51 Correct 43 ms 8128 KB Output is correct
52 Correct 45 ms 8300 KB Output is correct
53 Correct 19 ms 3392 KB Output is correct
54 Correct 7 ms 2816 KB Output is correct
55 Correct 8 ms 3136 KB Output is correct
56 Correct 16 ms 3712 KB Output is correct
57 Correct 177 ms 89772 KB Output is correct
58 Correct 13 ms 3772 KB Output is correct
59 Correct 17 ms 4664 KB Output is correct
60 Correct 26 ms 5552 KB Output is correct
61 Correct 17 ms 4224 KB Output is correct
62 Correct 30 ms 9372 KB Output is correct
63 Correct 76 ms 37940 KB Output is correct
64 Correct 89 ms 51124 KB Output is correct
65 Correct 122 ms 60336 KB Output is correct
66 Correct 195 ms 106596 KB Output is correct
67 Correct 196 ms 110552 KB Output is correct