Submission #400785

# Submission time Handle Problem Language Result Execution time Memory
400785 2021-05-08T16:12:48 Z BERNARB01 Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
855 ms 64068 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2003;
const long long inf = (long long) 8e18L;

long long g[N][N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			g[i][j] = inf;
		}
	}
	int target, start;
	for (int i = 0; i < m; i++) {
		int b, p;
		cin >> b >> p;
		if (i == 0) { 
			start = b;
		}
		if (i == 1) {
			target = b;
		}
		for (int j = 0; j < n; j++) {
			int d = abs(b - j);
			if (d % p == 0) {
				g[b][j] = min(g[b][j], (long long) d / p);
			}
		}
	}
	vector<long long> dist(n, inf);
	priority_queue<pair<long long, int>> s;
	dist[start] = 0;
	s.emplace(0, start);
	while (!s.empty()) {
		long long exp = -s.top().first;
		int u = s.top().second;
		s.pop();
		if (exp != dist[u]) {
			continue;
		}
		for (int v = 0; v < n; v++) {
			if (dist[u] + g[u][v] < dist[v]) {
				dist[v] = dist[u] + g[u][v];
				s.emplace(-dist[v], v);
			}
		}
	}
	cout << (dist[target] >= inf ? -1 : dist[target]) << '\n';
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:55:22: warning: 'target' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |  cout << (dist[target] >= inf ? -1 : dist[target]) << '\n';
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 3 ms 800 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 13 ms 7628 KB Output is correct
18 Correct 23 ms 27656 KB Output is correct
19 Correct 24 ms 31676 KB Output is correct
20 Correct 77 ms 31684 KB Output is correct
21 Correct 5 ms 3020 KB Output is correct
22 Correct 22 ms 28156 KB Output is correct
23 Correct 25 ms 25400 KB Output is correct
24 Correct 41 ms 30128 KB Output is correct
25 Correct 44 ms 31660 KB Output is correct
26 Correct 75 ms 31668 KB Output is correct
27 Correct 76 ms 31684 KB Output is correct
28 Correct 45 ms 31680 KB Output is correct
29 Correct 33 ms 31820 KB Output is correct
30 Correct 25 ms 31800 KB Output is correct
31 Correct 30 ms 31804 KB Output is correct
32 Correct 32 ms 31692 KB Output is correct
33 Correct 49 ms 31816 KB Output is correct
34 Correct 48 ms 31788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 2 ms 1360 KB Output is correct
17 Correct 13 ms 7596 KB Output is correct
18 Correct 24 ms 27724 KB Output is correct
19 Correct 24 ms 31672 KB Output is correct
20 Correct 79 ms 31664 KB Output is correct
21 Correct 5 ms 3020 KB Output is correct
22 Correct 25 ms 28236 KB Output is correct
23 Correct 26 ms 25420 KB Output is correct
24 Correct 42 ms 30128 KB Output is correct
25 Correct 44 ms 31656 KB Output is correct
26 Correct 74 ms 31672 KB Output is correct
27 Correct 73 ms 31676 KB Output is correct
28 Correct 48 ms 31672 KB Output is correct
29 Correct 33 ms 31808 KB Output is correct
30 Correct 25 ms 31804 KB Output is correct
31 Correct 31 ms 31744 KB Output is correct
32 Correct 29 ms 31808 KB Output is correct
33 Correct 49 ms 31812 KB Output is correct
34 Correct 48 ms 31788 KB Output is correct
35 Correct 221 ms 22300 KB Output is correct
36 Correct 38 ms 14020 KB Output is correct
37 Correct 237 ms 30828 KB Output is correct
38 Correct 352 ms 31776 KB Output is correct
39 Correct 362 ms 31812 KB Output is correct
40 Correct 353 ms 31780 KB Output is correct
41 Correct 360 ms 31812 KB Output is correct
42 Correct 844 ms 31872 KB Output is correct
43 Correct 830 ms 31936 KB Output is correct
44 Correct 850 ms 31936 KB Output is correct
45 Correct 370 ms 31936 KB Output is correct
46 Correct 370 ms 31928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 13 ms 7612 KB Output is correct
18 Correct 25 ms 27712 KB Output is correct
19 Correct 23 ms 31676 KB Output is correct
20 Correct 76 ms 31684 KB Output is correct
21 Correct 5 ms 3020 KB Output is correct
22 Correct 21 ms 28248 KB Output is correct
23 Correct 26 ms 25420 KB Output is correct
24 Correct 43 ms 30116 KB Output is correct
25 Correct 44 ms 31672 KB Output is correct
26 Correct 74 ms 31668 KB Output is correct
27 Correct 71 ms 31660 KB Output is correct
28 Correct 45 ms 31652 KB Output is correct
29 Correct 33 ms 31808 KB Output is correct
30 Correct 25 ms 31820 KB Output is correct
31 Correct 30 ms 31820 KB Output is correct
32 Correct 29 ms 31824 KB Output is correct
33 Correct 49 ms 31804 KB Output is correct
34 Correct 48 ms 31776 KB Output is correct
35 Correct 217 ms 22224 KB Output is correct
36 Correct 38 ms 14020 KB Output is correct
37 Correct 235 ms 30816 KB Output is correct
38 Correct 357 ms 31736 KB Output is correct
39 Correct 357 ms 31784 KB Output is correct
40 Correct 355 ms 31808 KB Output is correct
41 Correct 356 ms 31884 KB Output is correct
42 Correct 839 ms 31944 KB Output is correct
43 Correct 835 ms 31864 KB Output is correct
44 Correct 855 ms 31940 KB Output is correct
45 Correct 370 ms 32000 KB Output is correct
46 Correct 371 ms 31940 KB Output is correct
47 Runtime error 60 ms 64068 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -