Submission #361388

# Submission time Handle Problem Language Result Execution time Memory
361388 2021-01-29T17:08:42 Z cabbagecabbagecabbage Jakarta Skyscrapers (APIO15_skyscraper) C++11
57 / 100
1000 ms 3300 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define in(a) cin >> a
#define in2(a,b) cin >> a >> b
#define in3(a,b,c) cin >> a >> b >> c
#define out(a) cout << a << el
#define out2(a, b) cout << a << " " << b << el
#define f(a) for (int i = 0; i < a; i++)
#define ff(a) for (int j = 0; j < a; j++)
#define f2(a, b) for (int i = a; i < b; i++)
#define ff2(a, b) for (int j = a; j < b; j++)
#define fb(a) for (int i = a - 1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define infb 0x3f
#define elif else if
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define el "\n"
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int,int>> vpii;
typedef tuple<int,int,int> tiii;

/*
skyscrapers as nodes
go from the skyscraper of the 1st doge to the skyscraper of the 2nd doge (i mean 0 and 1)
edges: for each doge in the skyscraper, try to make every jump possible, even more than 1 jump
*/

const int nax = 3e4 + 5;

int n,m,b,p,s,e;
vi doges[nax];
priority_queue<pii,vector<pii>,greater<pii>> q;
int dist[nax];


int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	in2(n,m);
	in2(b,p);
	s = b;
	doges[b].eb(p);
	in2(b,p);
	e = b;
	doges[b].eb(p);
	f2(2,m){
		in2(b,p);
		doges[b].eb(p);
	}
	
	mem(dist,infb);
	dist[s] = 0;
	q.emplace(0,s);
	int cost, node, newcost, location;
	while (!q.empty()){
		tie(cost, node) = q.top(); q.pop();
		if (node == e){
			out(cost);
			return 0;
		}
		if (cost != dist[node]) continue;
		for (int doge: doges[node]){
			for (int jumps = 1; (location = node + jumps*doge) <= n-1; jumps++){ //try defining location here
				newcost = cost + jumps;
				if (newcost < dist[location]){
					q.emplace(newcost,location);
					dist[location] = newcost;
				}
			}
			for (int jumps = 1; (location = node - jumps*doge) >= 0; jumps++){
				newcost = cost + jumps;
				if (newcost < dist[location]){
					q.emplace(newcost,location);
					dist[location] = newcost;
				}
			}
		}
	}
		
	out(-1);


	return 0;
}




















//trailing lines ftw
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 2 ms 1132 KB Output is correct
17 Correct 2 ms 1260 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 6 ms 1260 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
27 Correct 1 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 3 ms 1388 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 2 ms 1260 KB Output is correct
32 Correct 2 ms 1260 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1260 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1260 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 2 ms 1260 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 6 ms 1260 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 3 ms 1388 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 2 ms 1260 KB Output is correct
32 Correct 2 ms 1260 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
35 Correct 7 ms 1644 KB Output is correct
36 Correct 2 ms 1260 KB Output is correct
37 Correct 7 ms 1644 KB Output is correct
38 Correct 11 ms 1772 KB Output is correct
39 Correct 7 ms 1644 KB Output is correct
40 Correct 8 ms 1656 KB Output is correct
41 Correct 8 ms 1772 KB Output is correct
42 Correct 6 ms 1644 KB Output is correct
43 Correct 6 ms 1644 KB Output is correct
44 Correct 63 ms 1772 KB Output is correct
45 Correct 8 ms 1772 KB Output is correct
46 Correct 8 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1136 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 2 ms 1260 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 7 ms 1260 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 3 ms 1388 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 2 ms 1260 KB Output is correct
32 Correct 2 ms 1260 KB Output is correct
33 Correct 4 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
35 Correct 7 ms 1644 KB Output is correct
36 Correct 3 ms 1260 KB Output is correct
37 Correct 6 ms 1644 KB Output is correct
38 Correct 8 ms 1772 KB Output is correct
39 Correct 7 ms 1644 KB Output is correct
40 Correct 7 ms 1644 KB Output is correct
41 Correct 8 ms 1772 KB Output is correct
42 Correct 6 ms 1644 KB Output is correct
43 Correct 6 ms 1644 KB Output is correct
44 Correct 61 ms 1644 KB Output is correct
45 Correct 9 ms 1772 KB Output is correct
46 Correct 8 ms 1772 KB Output is correct
47 Correct 13 ms 2408 KB Output is correct
48 Correct 8 ms 1900 KB Output is correct
49 Correct 7 ms 1772 KB Output is correct
50 Correct 6 ms 1644 KB Output is correct
51 Correct 17 ms 3300 KB Output is correct
52 Correct 18 ms 2792 KB Output is correct
53 Correct 10 ms 2412 KB Output is correct
54 Correct 3 ms 1388 KB Output is correct
55 Correct 3 ms 1388 KB Output is correct
56 Correct 903 ms 2672 KB Output is correct
57 Correct 4 ms 1896 KB Output is correct
58 Execution timed out 1012 ms 1644 KB Time limit exceeded
59 Halted 0 ms 0 KB -