Submission #32937

# Submission time Handle Problem Language Result Execution time Memory
32937 2017-10-17T17:08:31 Z minimario Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
293 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pii;
typedef long long ll;
 
#define f first
#define s second
 
const int MAX = 30005;
const int SQRT = 90;
const int INF = 1000000000;
int p[MAX], len[MAX]; // position, length
 
vector<pair<int, int> > g[MAX];
vector<int> powers[MAX]; // powers of doges at a given position
 
int dist[MAX];
 
priority_queue<pair<int, int> > pq;

void dijk(int i) {
	dist[i] = 0;
	pq.push({0, i});
	while (!pq.empty()) {
		auto top = pq.top(); pq.pop();
		int d = -top.f;
		int loc = top.s;
		if (d > dist[loc]) {
			continue; 
		}
		for (auto i : g[loc]) {
			int d_new = (d + i.s);
			if (d_new < dist[i.f]) {
				dist[i.f] = d_new;
				pq.push({-d_new, i.f});
			}
		}
	}
}

map<int, bool> l[MAX], r[MAX];
int main() {
	// freopen("a.in", "r", stdin);
	// freopen("a.out", "w", stdout);
 
	int n, m; scanf("%d %d", &n, &m);
	for (int i=0; i<m; i++) {
		scanf("%d %d", &p[i], &len[i]);
		if (!r[p[i]][len[i]]) {
			for (int j=p[i]+len[i]; j<n; j+=len[i]) {
				r[j][len[i]] = true;
				g[p[i]].push_back({j, (j-p[i])/len[i]});
			}
		}
		if (!l[p[i]][len[i]]) {
			for (int j=p[i]-len[i]; j>=0; j-=len[i]) {
				l[j][len[i]] = true;
				g[p[i]].push_back({j, (p[i]-j)/len[i]});
			}
		}
	}
	for (int i=0; i<MAX; i++) { dist[i] = INF; }
	dijk(p[0]);
	if (dist[p[1]] == INF) { printf("%d\n", -1); }
	else { printf("%d\n", dist[p[1]]); }
}	

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, m; scanf("%d %d", &n, &m);
                                  ^
skyscraper.cpp:49:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p[i], &len[i]);
                                 ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 3 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
8 Correct 0 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 3 ms 6720 KB Output is correct
11 Correct 0 ms 6984 KB Output is correct
12 Correct 3 ms 9760 KB Output is correct
13 Correct 3 ms 6588 KB Output is correct
14 Correct 3 ms 6984 KB Output is correct
15 Correct 3 ms 6984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 3 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 3 ms 6588 KB Output is correct
8 Correct 3 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 0 ms 6720 KB Output is correct
11 Correct 3 ms 6984 KB Output is correct
12 Correct 6 ms 9760 KB Output is correct
13 Correct 0 ms 6588 KB Output is correct
14 Correct 3 ms 6984 KB Output is correct
15 Correct 0 ms 6984 KB Output is correct
16 Correct 0 ms 6852 KB Output is correct
17 Correct 6 ms 7644 KB Output is correct
18 Correct 3 ms 6984 KB Output is correct
19 Correct 0 ms 6852 KB Output is correct
20 Correct 3 ms 6852 KB Output is correct
21 Correct 0 ms 6852 KB Output is correct
22 Correct 3 ms 6984 KB Output is correct
23 Correct 3 ms 6988 KB Output is correct
24 Correct 3 ms 7512 KB Output is correct
25 Correct 3 ms 7248 KB Output is correct
26 Correct 9 ms 10316 KB Output is correct
27 Correct 59 ms 56196 KB Output is correct
28 Correct 0 ms 8044 KB Output is correct
29 Correct 16 ms 10488 KB Output is correct
30 Correct 3 ms 7780 KB Output is correct
31 Correct 13 ms 8732 KB Output is correct
32 Correct 9 ms 8180 KB Output is correct
33 Correct 53 ms 13972 KB Output is correct
34 Correct 46 ms 14016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 3 ms 6588 KB Output is correct
5 Correct 3 ms 6588 KB Output is correct
6 Correct 3 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
8 Correct 0 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 0 ms 6720 KB Output is correct
11 Correct 3 ms 6984 KB Output is correct
12 Correct 3 ms 9760 KB Output is correct
13 Correct 3 ms 6588 KB Output is correct
14 Correct 0 ms 6984 KB Output is correct
15 Correct 0 ms 6984 KB Output is correct
16 Correct 0 ms 6852 KB Output is correct
17 Correct 9 ms 7644 KB Output is correct
18 Correct 0 ms 6984 KB Output is correct
19 Correct 0 ms 6852 KB Output is correct
20 Correct 3 ms 6852 KB Output is correct
21 Correct 0 ms 6852 KB Output is correct
22 Correct 3 ms 6984 KB Output is correct
23 Correct 0 ms 6988 KB Output is correct
24 Correct 6 ms 7512 KB Output is correct
25 Correct 0 ms 7248 KB Output is correct
26 Correct 6 ms 10316 KB Output is correct
27 Correct 83 ms 56196 KB Output is correct
28 Correct 6 ms 8044 KB Output is correct
29 Correct 19 ms 10488 KB Output is correct
30 Correct 0 ms 7780 KB Output is correct
31 Correct 6 ms 8732 KB Output is correct
32 Correct 9 ms 8180 KB Output is correct
33 Correct 53 ms 13972 KB Output is correct
34 Correct 56 ms 14016 KB Output is correct
35 Correct 76 ms 14248 KB Output is correct
36 Correct 9 ms 7908 KB Output is correct
37 Correct 139 ms 18868 KB Output is correct
38 Correct 183 ms 18348 KB Output is correct
39 Correct 163 ms 18508 KB Output is correct
40 Correct 156 ms 18404 KB Output is correct
41 Correct 123 ms 18204 KB Output is correct
42 Correct 79 ms 56396 KB Output is correct
43 Memory limit exceeded 293 ms 262144 KB Memory limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
8 Correct 0 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 0 ms 6720 KB Output is correct
11 Correct 0 ms 6984 KB Output is correct
12 Correct 0 ms 9760 KB Output is correct
13 Correct 0 ms 6588 KB Output is correct
14 Correct 3 ms 6984 KB Output is correct
15 Correct 0 ms 6984 KB Output is correct
16 Correct 0 ms 6852 KB Output is correct
17 Correct 3 ms 7644 KB Output is correct
18 Correct 3 ms 6984 KB Output is correct
19 Correct 3 ms 6852 KB Output is correct
20 Correct 3 ms 6852 KB Output is correct
21 Correct 0 ms 6852 KB Output is correct
22 Correct 0 ms 6984 KB Output is correct
23 Correct 0 ms 6988 KB Output is correct
24 Correct 6 ms 7512 KB Output is correct
25 Correct 0 ms 7248 KB Output is correct
26 Correct 6 ms 10316 KB Output is correct
27 Correct 66 ms 56196 KB Output is correct
28 Correct 6 ms 8044 KB Output is correct
29 Correct 26 ms 10488 KB Output is correct
30 Correct 3 ms 7780 KB Output is correct
31 Correct 6 ms 8732 KB Output is correct
32 Correct 3 ms 8180 KB Output is correct
33 Correct 59 ms 13972 KB Output is correct
34 Correct 59 ms 14016 KB Output is correct
35 Correct 83 ms 14248 KB Output is correct
36 Correct 3 ms 7908 KB Output is correct
37 Correct 156 ms 18868 KB Output is correct
38 Correct 169 ms 18348 KB Output is correct
39 Correct 173 ms 18508 KB Output is correct
40 Correct 176 ms 18404 KB Output is correct
41 Correct 149 ms 18204 KB Output is correct
42 Correct 63 ms 56396 KB Output is correct
43 Memory limit exceeded 273 ms 262144 KB Memory limit exceeded
44 Halted 0 ms 0 KB -