Submission #197309

# Submission time Handle Problem Language Result Execution time Memory
197309 2020-01-20T09:37:58 Z Juney Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
265 ms 72148 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3e4 + 5;

int N, M, B[MAXN], D[MAXN], S, E;
vector<int> V[MAXN];
vector<pii> G[MAXN];

void solve() {
	for(int i=0; i<N; i++) D[i] = 1e9;
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	D[S] = 0;
	pq.push(pii(0, S));
	while(!pq.empty()) {
		int cur = pq.top().se, dis = pq.top().fi; pq.pop();
		if(D[cur] < dis) continue;
		for(auto nxt : G[cur]) if(dis + nxt.se < D[nxt.fi]) {
			D[nxt.fi] = dis + nxt.se;
			pq.push(pii(D[nxt.fi], nxt.fi));
		}
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	for(int i=0; i<M; i++) {
		int b, p;
		cin >> b >> p;
		V[p].push_back(b);
		if(i == 0) S = b;
		if(i == 1) E = b;
	}
	for(int i=1; i<=30000; i++) {
		for(int j : V[i]) B[j] = i;
		sort(V[i].begin(), V[i].end());
		V[i].erase(unique(V[i].begin(), V[i].end()), V[i].end());
		for(int j=0; j<V[i].size(); j++) {
			for(int b=V[i][j]+i, dis=1; b<N; b+=i, dis++) {
				G[V[i][j]].push_back(pii(b, dis));
				if(B[b] == i) break;
			}
			for(int b=V[i][j]-i, dis=1; b>=0; b-=i, dis++) {
				G[V[i][j]].push_back(pii(b, dis));
				if(B[b] == i) break;
			}
		}
	}
	solve();
	if(D[E] == (int)1e9) cout << -1;
	else cout << D[E];
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<V[i].size(); j++) {
                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1784 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 3 ms 1784 KB Output is correct
6 Correct 3 ms 1788 KB Output is correct
7 Correct 3 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1784 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 3 ms 1784 KB Output is correct
6 Correct 3 ms 1784 KB Output is correct
7 Correct 3 ms 1784 KB Output is correct
8 Correct 3 ms 1784 KB Output is correct
9 Correct 3 ms 1784 KB Output is correct
10 Correct 4 ms 1784 KB Output is correct
11 Correct 4 ms 1784 KB Output is correct
12 Correct 4 ms 1784 KB Output is correct
13 Correct 4 ms 1784 KB Output is correct
14 Correct 4 ms 1784 KB Output is correct
15 Correct 4 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1784 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 3 ms 1784 KB Output is correct
6 Correct 4 ms 1784 KB Output is correct
7 Correct 2 ms 1784 KB Output is correct
8 Correct 3 ms 1784 KB Output is correct
9 Correct 4 ms 1784 KB Output is correct
10 Correct 3 ms 1784 KB Output is correct
11 Correct 4 ms 1784 KB Output is correct
12 Correct 4 ms 1784 KB Output is correct
13 Correct 4 ms 1784 KB Output is correct
14 Correct 4 ms 1912 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 4 ms 1788 KB Output is correct
17 Correct 5 ms 2040 KB Output is correct
18 Correct 4 ms 1916 KB Output is correct
19 Correct 4 ms 1912 KB Output is correct
20 Correct 4 ms 1784 KB Output is correct
21 Correct 4 ms 1784 KB Output is correct
22 Correct 4 ms 1784 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 1912 KB Output is correct
25 Correct 5 ms 2040 KB Output is correct
26 Correct 4 ms 1912 KB Output is correct
27 Correct 4 ms 1932 KB Output is correct
28 Correct 5 ms 2040 KB Output is correct
29 Correct 7 ms 2552 KB Output is correct
30 Correct 5 ms 2168 KB Output is correct
31 Correct 5 ms 2296 KB Output is correct
32 Correct 3 ms 2168 KB Output is correct
33 Correct 10 ms 3400 KB Output is correct
34 Correct 10 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1756 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1784 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 3 ms 1784 KB Output is correct
6 Correct 3 ms 1784 KB Output is correct
7 Correct 3 ms 1784 KB Output is correct
8 Correct 3 ms 1788 KB Output is correct
9 Correct 3 ms 1784 KB Output is correct
10 Correct 4 ms 1784 KB Output is correct
11 Correct 4 ms 1784 KB Output is correct
12 Correct 4 ms 1784 KB Output is correct
13 Correct 4 ms 1784 KB Output is correct
14 Correct 4 ms 1912 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 4 ms 1784 KB Output is correct
17 Correct 5 ms 2040 KB Output is correct
18 Correct 4 ms 1912 KB Output is correct
19 Correct 4 ms 1784 KB Output is correct
20 Correct 4 ms 1912 KB Output is correct
21 Correct 4 ms 1784 KB Output is correct
22 Correct 4 ms 1912 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 2040 KB Output is correct
25 Correct 5 ms 2040 KB Output is correct
26 Correct 4 ms 1912 KB Output is correct
27 Correct 4 ms 1912 KB Output is correct
28 Correct 5 ms 2040 KB Output is correct
29 Correct 7 ms 2552 KB Output is correct
30 Correct 5 ms 2040 KB Output is correct
31 Correct 5 ms 2168 KB Output is correct
32 Correct 5 ms 2168 KB Output is correct
33 Correct 10 ms 3320 KB Output is correct
34 Correct 10 ms 3320 KB Output is correct
35 Correct 14 ms 3192 KB Output is correct
36 Correct 6 ms 2040 KB Output is correct
37 Correct 15 ms 4220 KB Output is correct
38 Correct 18 ms 4112 KB Output is correct
39 Correct 32 ms 4088 KB Output is correct
40 Correct 19 ms 4088 KB Output is correct
41 Correct 17 ms 4088 KB Output is correct
42 Correct 11 ms 2296 KB Output is correct
43 Correct 10 ms 2168 KB Output is correct
44 Correct 9 ms 2296 KB Output is correct
45 Correct 24 ms 6776 KB Output is correct
46 Correct 24 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 4 ms 1784 KB Output is correct
3 Correct 4 ms 1784 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 3 ms 1784 KB Output is correct
6 Correct 3 ms 1784 KB Output is correct
7 Correct 3 ms 1784 KB Output is correct
8 Correct 3 ms 1784 KB Output is correct
9 Correct 3 ms 1784 KB Output is correct
10 Correct 3 ms 1784 KB Output is correct
11 Correct 4 ms 1912 KB Output is correct
12 Correct 4 ms 1784 KB Output is correct
13 Correct 4 ms 1784 KB Output is correct
14 Correct 4 ms 1784 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 4 ms 1784 KB Output is correct
17 Correct 5 ms 2044 KB Output is correct
18 Correct 4 ms 1912 KB Output is correct
19 Correct 4 ms 1784 KB Output is correct
20 Correct 4 ms 1912 KB Output is correct
21 Correct 4 ms 1784 KB Output is correct
22 Correct 4 ms 1656 KB Output is correct
23 Correct 4 ms 1912 KB Output is correct
24 Correct 5 ms 1912 KB Output is correct
25 Correct 6 ms 2040 KB Output is correct
26 Correct 4 ms 1912 KB Output is correct
27 Correct 4 ms 1912 KB Output is correct
28 Correct 5 ms 2040 KB Output is correct
29 Correct 7 ms 2680 KB Output is correct
30 Correct 5 ms 2040 KB Output is correct
31 Correct 4 ms 2296 KB Output is correct
32 Correct 5 ms 2040 KB Output is correct
33 Correct 10 ms 3320 KB Output is correct
34 Correct 10 ms 3320 KB Output is correct
35 Correct 14 ms 3192 KB Output is correct
36 Correct 6 ms 2040 KB Output is correct
37 Correct 15 ms 4216 KB Output is correct
38 Correct 17 ms 4084 KB Output is correct
39 Correct 18 ms 4092 KB Output is correct
40 Correct 17 ms 4088 KB Output is correct
41 Correct 18 ms 4088 KB Output is correct
42 Correct 9 ms 2168 KB Output is correct
43 Correct 9 ms 2296 KB Output is correct
44 Correct 10 ms 2296 KB Output is correct
45 Correct 24 ms 6776 KB Output is correct
46 Correct 24 ms 6904 KB Output is correct
47 Correct 43 ms 11384 KB Output is correct
48 Correct 20 ms 4980 KB Output is correct
49 Correct 17 ms 4088 KB Output is correct
50 Correct 14 ms 3960 KB Output is correct
51 Correct 46 ms 6840 KB Output is correct
52 Correct 48 ms 7164 KB Output is correct
53 Correct 22 ms 4116 KB Output is correct
54 Correct 6 ms 2424 KB Output is correct
55 Correct 7 ms 2804 KB Output is correct
56 Correct 16 ms 3320 KB Output is correct
57 Correct 47 ms 11008 KB Output is correct
58 Correct 13 ms 3060 KB Output is correct
59 Correct 15 ms 3572 KB Output is correct
60 Correct 17 ms 4340 KB Output is correct
61 Correct 16 ms 3700 KB Output is correct
62 Correct 28 ms 7540 KB Output is correct
63 Correct 96 ms 25824 KB Output is correct
64 Correct 112 ms 34156 KB Output is correct
65 Correct 143 ms 44392 KB Output is correct
66 Correct 264 ms 72116 KB Output is correct
67 Correct 265 ms 72148 KB Output is correct