Submission #68806

# Submission time Handle Problem Language Result Execution time Memory
68806 2018-08-18T14:14:05 Z FedericoS Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 2548 KB
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<pair<int,int>,int> pp;

int N,M;
int B[30005],P[30005];
vector<int> V[30005];
priority_queue<pp> Q;

int main(){

	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>B[i]>>P[i];
		if(i)
			V[B[i]].push_back(i);
	}

	//dist pos ind


	Q.push({{0,B[0]},0});

	while(!Q.empty()){

		pp p=Q.top();
		Q.pop();

		//cout<<Q.size()<<" "<<p.second<<" "<<p.first.first<<" "<<p.first.second<<endl;

		if(p.second==1){
			cout<<-p.first.first;
			return 0;
		}

		for(int x:V[p.first.second])
			Q.push({{p.first.first,B[x]},x});
		V[p.first.second].clear();

		if(p.first.second==B[p.second]){

			for(int k=1;;k++){
				if(p.first.second-k*P[p.second]<0)
					break;
				if(!V[p.first.second-k*P[p.second]].empty()){
					Q.push({{p.first.first-k,p.first.second-k*P[p.second]},p.second});
					break;
				}
			}

			for(int k=1;;k++){
				if(p.first.second+k*P[p.second]>=N)
					break;
				if(!V[p.first.second+k*P[p.second]].empty()){
					Q.push({{p.first.first-k,p.first.second+k*P[p.second]},p.second});
					break;
				}
			}			

		}

		if(p.first.second<B[p.second]){
			
			for(int k=1;;k++){
				if(p.first.second-k*P[p.second]<0)
					break;
				if(!V[p.first.second-k*P[p.second]].empty()){
					Q.push({{p.first.first-k,p.first.second-k*P[p.second]},p.second});
					break;
				}
			}

		}

		if(p.first.second>B[p.second]){
			
			for(int k=1;;k++){
				if(p.first.second+k*P[p.second]>=N)
					break;
				if(!V[p.first.second+k*P[p.second]].empty()){
					Q.push({{p.first.first-k,p.first.second+k*P[p.second]},p.second});
					break;
				}
			}	

		}

	}

	cout<<-1;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1208 KB Output is correct
3 Correct 4 ms 1208 KB Output is correct
4 Correct 4 ms 1240 KB Output is correct
5 Correct 4 ms 1240 KB Output is correct
6 Correct 3 ms 1268 KB Output is correct
7 Correct 4 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1296 KB Output is correct
2 Correct 4 ms 1296 KB Output is correct
3 Correct 3 ms 1296 KB Output is correct
4 Correct 3 ms 1296 KB Output is correct
5 Correct 3 ms 1296 KB Output is correct
6 Correct 2 ms 1296 KB Output is correct
7 Correct 4 ms 1296 KB Output is correct
8 Correct 4 ms 1296 KB Output is correct
9 Correct 4 ms 1296 KB Output is correct
10 Correct 3 ms 1296 KB Output is correct
11 Correct 4 ms 1296 KB Output is correct
12 Correct 5 ms 1384 KB Output is correct
13 Correct 5 ms 1388 KB Output is correct
14 Correct 5 ms 1388 KB Output is correct
15 Correct 5 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1388 KB Output is correct
2 Correct 4 ms 1388 KB Output is correct
3 Correct 3 ms 1388 KB Output is correct
4 Correct 4 ms 1388 KB Output is correct
5 Correct 2 ms 1388 KB Output is correct
6 Correct 4 ms 1388 KB Output is correct
7 Correct 3 ms 1388 KB Output is correct
8 Correct 3 ms 1388 KB Output is correct
9 Correct 3 ms 1388 KB Output is correct
10 Correct 3 ms 1388 KB Output is correct
11 Correct 4 ms 1388 KB Output is correct
12 Correct 6 ms 1404 KB Output is correct
13 Correct 6 ms 1404 KB Output is correct
14 Correct 5 ms 1404 KB Output is correct
15 Correct 4 ms 1404 KB Output is correct
16 Correct 4 ms 1404 KB Output is correct
17 Correct 5 ms 1404 KB Output is correct
18 Correct 4 ms 1404 KB Output is correct
19 Correct 5 ms 1404 KB Output is correct
20 Correct 325 ms 1532 KB Output is correct
21 Correct 4 ms 1532 KB Output is correct
22 Correct 4 ms 1532 KB Output is correct
23 Correct 4 ms 1532 KB Output is correct
24 Correct 5 ms 1532 KB Output is correct
25 Correct 4 ms 1532 KB Output is correct
26 Correct 5 ms 1532 KB Output is correct
27 Correct 9 ms 1532 KB Output is correct
28 Correct 5 ms 1532 KB Output is correct
29 Correct 3 ms 1532 KB Output is correct
30 Correct 4 ms 1532 KB Output is correct
31 Correct 4 ms 1532 KB Output is correct
32 Correct 4 ms 1532 KB Output is correct
33 Correct 5 ms 1532 KB Output is correct
34 Correct 5 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1532 KB Output is correct
2 Correct 3 ms 1532 KB Output is correct
3 Correct 3 ms 1532 KB Output is correct
4 Correct 3 ms 1532 KB Output is correct
5 Correct 3 ms 1532 KB Output is correct
6 Correct 3 ms 1532 KB Output is correct
7 Correct 3 ms 1532 KB Output is correct
8 Correct 4 ms 1532 KB Output is correct
9 Correct 4 ms 1532 KB Output is correct
10 Correct 3 ms 1532 KB Output is correct
11 Correct 6 ms 1532 KB Output is correct
12 Correct 4 ms 1532 KB Output is correct
13 Correct 5 ms 1532 KB Output is correct
14 Correct 4 ms 1532 KB Output is correct
15 Correct 4 ms 1532 KB Output is correct
16 Correct 3 ms 1532 KB Output is correct
17 Correct 5 ms 1532 KB Output is correct
18 Correct 3 ms 1532 KB Output is correct
19 Correct 3 ms 1532 KB Output is correct
20 Correct 268 ms 1660 KB Output is correct
21 Correct 3 ms 1660 KB Output is correct
22 Correct 3 ms 1660 KB Output is correct
23 Correct 3 ms 1660 KB Output is correct
24 Correct 5 ms 1660 KB Output is correct
25 Correct 4 ms 1660 KB Output is correct
26 Correct 4 ms 1660 KB Output is correct
27 Correct 10 ms 1660 KB Output is correct
28 Correct 5 ms 1660 KB Output is correct
29 Correct 3 ms 1660 KB Output is correct
30 Correct 3 ms 1660 KB Output is correct
31 Correct 4 ms 1660 KB Output is correct
32 Correct 3 ms 1660 KB Output is correct
33 Correct 4 ms 1660 KB Output is correct
34 Correct 5 ms 1660 KB Output is correct
35 Correct 23 ms 1916 KB Output is correct
36 Correct 7 ms 1916 KB Output is correct
37 Correct 17 ms 1916 KB Output is correct
38 Correct 38 ms 2104 KB Output is correct
39 Correct 23 ms 2104 KB Output is correct
40 Correct 25 ms 2104 KB Output is correct
41 Correct 32 ms 2108 KB Output is correct
42 Correct 31 ms 2108 KB Output is correct
43 Correct 99 ms 2168 KB Output is correct
44 Correct 339 ms 2260 KB Output is correct
45 Correct 26 ms 2260 KB Output is correct
46 Correct 29 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 3 ms 2260 KB Output is correct
9 Correct 4 ms 2260 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 5 ms 2260 KB Output is correct
12 Correct 4 ms 2260 KB Output is correct
13 Correct 5 ms 2260 KB Output is correct
14 Correct 5 ms 2260 KB Output is correct
15 Correct 6 ms 2260 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 5 ms 2260 KB Output is correct
18 Correct 3 ms 2260 KB Output is correct
19 Correct 4 ms 2260 KB Output is correct
20 Correct 276 ms 2260 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 5 ms 2260 KB Output is correct
24 Correct 6 ms 2260 KB Output is correct
25 Correct 6 ms 2260 KB Output is correct
26 Correct 6 ms 2260 KB Output is correct
27 Correct 10 ms 2260 KB Output is correct
28 Correct 5 ms 2260 KB Output is correct
29 Correct 4 ms 2260 KB Output is correct
30 Correct 4 ms 2260 KB Output is correct
31 Correct 4 ms 2260 KB Output is correct
32 Correct 5 ms 2260 KB Output is correct
33 Correct 5 ms 2260 KB Output is correct
34 Correct 5 ms 2260 KB Output is correct
35 Correct 25 ms 2260 KB Output is correct
36 Correct 7 ms 2260 KB Output is correct
37 Correct 28 ms 2260 KB Output is correct
38 Correct 30 ms 2260 KB Output is correct
39 Correct 26 ms 2260 KB Output is correct
40 Correct 25 ms 2260 KB Output is correct
41 Correct 39 ms 2260 KB Output is correct
42 Correct 23 ms 2260 KB Output is correct
43 Correct 97 ms 2260 KB Output is correct
44 Correct 359 ms 2264 KB Output is correct
45 Correct 24 ms 2264 KB Output is correct
46 Correct 22 ms 2264 KB Output is correct
47 Correct 39 ms 2264 KB Output is correct
48 Correct 27 ms 2264 KB Output is correct
49 Correct 33 ms 2264 KB Output is correct
50 Correct 17 ms 2264 KB Output is correct
51 Correct 45 ms 2300 KB Output is correct
52 Correct 52 ms 2416 KB Output is correct
53 Correct 34 ms 2416 KB Output is correct
54 Correct 3 ms 2416 KB Output is correct
55 Correct 4 ms 2416 KB Output is correct
56 Execution timed out 1085 ms 2548 KB Time limit exceeded
57 Halted 0 ms 0 KB -