답안 #281787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281787 2020-08-23T13:15:04 Z srvlt Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
676 ms 116344 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 30003, inf = 1e9, k0 = 7500000;
int n, m, num, ind[n0];
vector <int> rem[n0], vec[n0], out[n0];
int g1[k0], g2[k0], g3[k0], b[k0], d[k0];
deque <int> q;

void relax0(int v, int u) {
	if (d[u] > d[v]) {
		d[u] = d[v];
		q.push_front(u);
	}
}

void relax1(int v, int u) {
	if (d[u] > d[v] + 1) {
		d[u] = d[v] + 1;
		q.pb(u);
	}
}

void bfs(int x) {
	q.pb(x);
	for (int i = 0; i < num; i++)
		d[i] = inf;
	d[x] = 0;
	while (!q.empty()) {
		int v = q.front();
		q.pop_front();
		if (v < n) {
			for (int i : out[v]) relax0(v, i);
		}	else {
			if (g1[v]) relax1(v, v - 1);
			if (g2[v]) relax1(v, v + 1);
			relax0(v, g3[v]);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	cin >> n >> m;
	int s, f;
	for (int i = 0; i < m; i++) {
		int B, P;
		cin >> B >> P;
		if (i == 0) s = B;
		if (i == 1) f = B;
		vec[P].pb(B);
		rem[P].pb(B % P);
	}
	num = n;
	for (int i = 1; i < n0; i++) {
		cps(rem[i]);
		for (int j : rem[i])
			num += ((n - 1) - j) / i + 1;
	}
	assert(num < 7500000);
	int cur = n;
	for (int i = 1; i < n0; i++) {
		for (int j : rem[i]) {
			for (int k = j; k < n; k += i) {
				g1[cur] = (k != j);
				g2[cur] = (k + i < n);
				g3[cur] = k;
				ind[k] = cur++;
			}
		}
		for (int j : vec[i])
			out[j].pb(ind[j]);
	}
	bfs(s);
	if (d[f] == inf) cout << -1;
	else cout << d[f];
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:82:9: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   82 |  if (d[f] == inf) cout << -1;
      |      ~~~^
skyscraper.cpp:81:5: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |  bfs(s);
      |  ~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 2 ms 2560 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2560 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 3 ms 2560 KB Output is correct
11 Correct 2 ms 2560 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Correct 3 ms 2688 KB Output is correct
19 Correct 2 ms 2560 KB Output is correct
20 Correct 2 ms 2560 KB Output is correct
21 Correct 2 ms 2560 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 3 ms 2944 KB Output is correct
25 Correct 3 ms 2816 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2816 KB Output is correct
28 Correct 3 ms 2944 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 2 ms 2816 KB Output is correct
31 Correct 4 ms 3072 KB Output is correct
32 Correct 3 ms 2944 KB Output is correct
33 Correct 7 ms 4480 KB Output is correct
34 Correct 6 ms 4480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 3 ms 2560 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2560 KB Output is correct
20 Correct 3 ms 2560 KB Output is correct
21 Correct 3 ms 2560 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 3 ms 2816 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 3 ms 2944 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 3 ms 3072 KB Output is correct
32 Correct 3 ms 2944 KB Output is correct
33 Correct 6 ms 4480 KB Output is correct
34 Correct 6 ms 4608 KB Output is correct
35 Correct 14 ms 4864 KB Output is correct
36 Correct 5 ms 2944 KB Output is correct
37 Correct 15 ms 5760 KB Output is correct
38 Correct 18 ms 5760 KB Output is correct
39 Correct 18 ms 5760 KB Output is correct
40 Correct 18 ms 5760 KB Output is correct
41 Correct 18 ms 5760 KB Output is correct
42 Correct 8 ms 3072 KB Output is correct
43 Correct 8 ms 3072 KB Output is correct
44 Correct 8 ms 3072 KB Output is correct
45 Correct 34 ms 10624 KB Output is correct
46 Correct 34 ms 10624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2560 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 2 ms 2560 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2560 KB Output is correct
21 Correct 2 ms 2560 KB Output is correct
22 Correct 2 ms 2608 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 3 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 3 ms 2944 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 2 ms 2816 KB Output is correct
31 Correct 3 ms 3072 KB Output is correct
32 Correct 3 ms 2944 KB Output is correct
33 Correct 6 ms 4480 KB Output is correct
34 Correct 8 ms 4480 KB Output is correct
35 Correct 14 ms 4736 KB Output is correct
36 Correct 4 ms 2944 KB Output is correct
37 Correct 17 ms 5760 KB Output is correct
38 Correct 21 ms 5760 KB Output is correct
39 Correct 22 ms 5760 KB Output is correct
40 Correct 19 ms 5760 KB Output is correct
41 Correct 23 ms 5888 KB Output is correct
42 Correct 8 ms 3200 KB Output is correct
43 Correct 8 ms 3072 KB Output is correct
44 Correct 8 ms 3072 KB Output is correct
45 Correct 37 ms 10624 KB Output is correct
46 Correct 42 ms 10624 KB Output is correct
47 Correct 56 ms 15004 KB Output is correct
48 Correct 18 ms 7680 KB Output is correct
49 Correct 16 ms 6400 KB Output is correct
50 Correct 12 ms 6016 KB Output is correct
51 Correct 36 ms 9464 KB Output is correct
52 Correct 38 ms 9984 KB Output is correct
53 Correct 19 ms 5248 KB Output is correct
54 Correct 3 ms 3200 KB Output is correct
55 Correct 4 ms 3584 KB Output is correct
56 Correct 13 ms 4352 KB Output is correct
57 Correct 21 ms 9600 KB Output is correct
58 Correct 9 ms 4224 KB Output is correct
59 Correct 11 ms 4768 KB Output is correct
60 Correct 11 ms 5120 KB Output is correct
61 Correct 12 ms 5120 KB Output is correct
62 Correct 27 ms 11776 KB Output is correct
63 Correct 189 ms 39288 KB Output is correct
64 Correct 211 ms 47096 KB Output is correct
65 Correct 421 ms 66424 KB Output is correct
66 Correct 665 ms 116344 KB Output is correct
67 Correct 676 ms 116268 KB Output is correct