Submission #453335

# Submission time Handle Problem Language Result Execution time Memory
453335 2021-08-04T10:48:03 Z nonsensenonsense1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
485 ms 171460 KB
#include <cstdio>
#include <vector>
#include <deque>

struct node {
	int dist, step, pos;
	bool vis;
	node() {
		vis = false;
		dist = ~(1 << 31);
	}
};

const int N = 30000;
const int K = 180;
int n, m;
node g[K][N], d[N][K];
std::vector<node *> top[N];
std::deque<node *> dq;

void go(node *cur, node *to, bool w) 
{
	if (to->dist > cur->dist + w) {
		to->dist = cur->dist;
		if (w) {
			++to->dist;
			dq.push_back(to);
		}
		else dq.push_front(to);
	}
}

int main() 
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < K; ++i) for (int j = 0; j < N; ++j) {
		g[i][j].step = i;
		g[i][j].pos = j;
	}
	int s, t;
	for (int i = 0; i < m; ++i) {
		int b, p;
		scanf("%d%d", &b, &p);
		if (!i) s = b;
		if (i == 1) t = b;
		if (p < K) top[b].push_back(g[p] + b);
		else for (int j = b % p; j < N; j += p) {
			if (j == b) top[b].push_back(d[i] + j / p);
			d[i][j / p].step = p;
			d[i][j / p].pos = j;
		}
	}
	g[0][s].dist = 0;
	dq.push_back(g[0] + s);
	while (!dq.empty()) {
		node *cur = dq.front();
		dq.pop_front();
		if (!cur->vis) {
			cur->vis = true;
			if (cur >= g[0] && cur < g[1]) for (int i = 0; i < (int)top[cur->pos].size(); ++i) go(cur, top[cur->pos][i], 0);
			else {
				go(cur, g[0] + cur->pos, 0);
				if (cur->pos - cur->step >= 0) go(cur, cur >= g[0] && cur < g[K] ? cur - cur->step : cur - 1, 1);
				if (cur->pos + cur->step < N) go(cur, cur >= g[0] && cur < g[K] ? cur + cur->step : cur + 1, 1);
			}
		}
	}
	if (g[0][t].dist == ~(1 << 31)) printf("-1\n");
	else printf("%d\n", g[0][t].dist);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d%d", &b, &p);
      |   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:68:14: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |  if (g[0][t].dist == ~(1 << 31)) printf("-1\n");
      |      ~~~~~~~~^~~~
skyscraper.cpp:54:22: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |  dq.push_back(g[0] + s);
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 102 ms 170040 KB Output is correct
2 Correct 101 ms 169956 KB Output is correct
3 Correct 102 ms 169952 KB Output is correct
4 Correct 102 ms 170040 KB Output is correct
5 Correct 102 ms 170160 KB Output is correct
6 Correct 104 ms 169952 KB Output is correct
7 Correct 106 ms 170040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 169948 KB Output is correct
2 Correct 103 ms 169996 KB Output is correct
3 Correct 102 ms 169960 KB Output is correct
4 Correct 105 ms 170032 KB Output is correct
5 Correct 104 ms 170028 KB Output is correct
6 Correct 112 ms 170040 KB Output is correct
7 Correct 106 ms 170084 KB Output is correct
8 Correct 104 ms 170040 KB Output is correct
9 Correct 107 ms 170040 KB Output is correct
10 Correct 127 ms 170008 KB Output is correct
11 Correct 161 ms 170124 KB Output is correct
12 Correct 114 ms 169988 KB Output is correct
13 Correct 104 ms 170096 KB Output is correct
14 Correct 150 ms 169976 KB Output is correct
15 Correct 148 ms 170168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 169952 KB Output is correct
2 Correct 102 ms 169924 KB Output is correct
3 Correct 102 ms 170024 KB Output is correct
4 Correct 103 ms 169928 KB Output is correct
5 Correct 101 ms 170044 KB Output is correct
6 Correct 103 ms 170008 KB Output is correct
7 Correct 103 ms 169924 KB Output is correct
8 Correct 105 ms 170028 KB Output is correct
9 Correct 119 ms 169952 KB Output is correct
10 Correct 126 ms 169948 KB Output is correct
11 Correct 161 ms 169976 KB Output is correct
12 Correct 108 ms 170028 KB Output is correct
13 Correct 102 ms 170060 KB Output is correct
14 Correct 149 ms 170028 KB Output is correct
15 Correct 149 ms 170152 KB Output is correct
16 Correct 104 ms 170044 KB Output is correct
17 Correct 142 ms 170108 KB Output is correct
18 Correct 102 ms 170152 KB Output is correct
19 Correct 104 ms 170072 KB Output is correct
20 Correct 103 ms 170132 KB Output is correct
21 Correct 102 ms 170052 KB Output is correct
22 Correct 103 ms 170096 KB Output is correct
23 Correct 109 ms 170068 KB Output is correct
24 Correct 120 ms 170088 KB Output is correct
25 Correct 105 ms 170052 KB Output is correct
26 Correct 111 ms 170000 KB Output is correct
27 Correct 107 ms 170052 KB Output is correct
28 Correct 117 ms 170128 KB Output is correct
29 Correct 131 ms 169972 KB Output is correct
30 Correct 111 ms 169964 KB Output is correct
31 Correct 120 ms 170052 KB Output is correct
32 Correct 110 ms 169956 KB Output is correct
33 Correct 152 ms 170096 KB Output is correct
34 Correct 155 ms 170064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 170012 KB Output is correct
2 Correct 102 ms 170024 KB Output is correct
3 Correct 104 ms 169928 KB Output is correct
4 Correct 102 ms 170004 KB Output is correct
5 Correct 104 ms 170032 KB Output is correct
6 Correct 102 ms 169924 KB Output is correct
7 Correct 104 ms 169984 KB Output is correct
8 Correct 102 ms 169984 KB Output is correct
9 Correct 108 ms 170056 KB Output is correct
10 Correct 127 ms 169992 KB Output is correct
11 Correct 161 ms 169976 KB Output is correct
12 Correct 104 ms 170052 KB Output is correct
13 Correct 103 ms 169992 KB Output is correct
14 Correct 153 ms 170040 KB Output is correct
15 Correct 150 ms 170092 KB Output is correct
16 Correct 106 ms 170028 KB Output is correct
17 Correct 147 ms 170168 KB Output is correct
18 Correct 103 ms 170048 KB Output is correct
19 Correct 104 ms 169948 KB Output is correct
20 Correct 104 ms 170116 KB Output is correct
21 Correct 103 ms 169988 KB Output is correct
22 Correct 101 ms 169972 KB Output is correct
23 Correct 108 ms 169976 KB Output is correct
24 Correct 118 ms 170092 KB Output is correct
25 Correct 107 ms 170192 KB Output is correct
26 Correct 107 ms 170052 KB Output is correct
27 Correct 108 ms 170092 KB Output is correct
28 Correct 119 ms 170072 KB Output is correct
29 Correct 128 ms 169960 KB Output is correct
30 Correct 107 ms 170052 KB Output is correct
31 Correct 113 ms 169968 KB Output is correct
32 Correct 113 ms 170116 KB Output is correct
33 Correct 150 ms 170000 KB Output is correct
34 Correct 158 ms 170100 KB Output is correct
35 Correct 289 ms 170900 KB Output is correct
36 Correct 137 ms 170132 KB Output is correct
37 Correct 283 ms 170680 KB Output is correct
38 Correct 282 ms 171000 KB Output is correct
39 Correct 270 ms 171108 KB Output is correct
40 Correct 275 ms 171188 KB Output is correct
41 Correct 275 ms 171120 KB Output is correct
42 Correct 115 ms 170672 KB Output is correct
43 Correct 113 ms 170868 KB Output is correct
44 Correct 108 ms 170616 KB Output is correct
45 Correct 454 ms 170864 KB Output is correct
46 Correct 485 ms 170864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 170004 KB Output is correct
2 Correct 105 ms 170092 KB Output is correct
3 Correct 107 ms 170024 KB Output is correct
4 Correct 101 ms 170052 KB Output is correct
5 Correct 105 ms 169956 KB Output is correct
6 Correct 104 ms 169964 KB Output is correct
7 Correct 101 ms 170048 KB Output is correct
8 Correct 103 ms 169964 KB Output is correct
9 Correct 107 ms 170012 KB Output is correct
10 Correct 127 ms 169952 KB Output is correct
11 Correct 157 ms 170052 KB Output is correct
12 Correct 105 ms 170040 KB Output is correct
13 Correct 103 ms 169996 KB Output is correct
14 Correct 150 ms 170024 KB Output is correct
15 Correct 161 ms 170052 KB Output is correct
16 Correct 103 ms 170052 KB Output is correct
17 Correct 140 ms 170036 KB Output is correct
18 Correct 103 ms 170064 KB Output is correct
19 Correct 102 ms 170048 KB Output is correct
20 Correct 105 ms 170092 KB Output is correct
21 Correct 104 ms 169972 KB Output is correct
22 Correct 101 ms 170052 KB Output is correct
23 Correct 111 ms 170048 KB Output is correct
24 Correct 116 ms 170048 KB Output is correct
25 Correct 109 ms 170120 KB Output is correct
26 Correct 109 ms 170080 KB Output is correct
27 Correct 109 ms 170020 KB Output is correct
28 Correct 120 ms 170076 KB Output is correct
29 Correct 135 ms 169992 KB Output is correct
30 Correct 104 ms 170000 KB Output is correct
31 Correct 114 ms 170092 KB Output is correct
32 Correct 113 ms 170004 KB Output is correct
33 Correct 154 ms 170032 KB Output is correct
34 Correct 163 ms 169984 KB Output is correct
35 Correct 249 ms 170908 KB Output is correct
36 Correct 140 ms 170148 KB Output is correct
37 Correct 283 ms 170788 KB Output is correct
38 Correct 279 ms 171208 KB Output is correct
39 Correct 273 ms 171132 KB Output is correct
40 Correct 281 ms 171340 KB Output is correct
41 Correct 275 ms 171112 KB Output is correct
42 Correct 115 ms 170556 KB Output is correct
43 Correct 113 ms 170644 KB Output is correct
44 Correct 115 ms 170544 KB Output is correct
45 Correct 474 ms 170868 KB Output is correct
46 Correct 442 ms 170872 KB Output is correct
47 Correct 249 ms 171080 KB Output is correct
48 Correct 113 ms 170772 KB Output is correct
49 Correct 112 ms 170740 KB Output is correct
50 Correct 117 ms 170532 KB Output is correct
51 Correct 137 ms 171024 KB Output is correct
52 Correct 139 ms 171076 KB Output is correct
53 Correct 118 ms 170976 KB Output is correct
54 Correct 100 ms 170020 KB Output is correct
55 Correct 104 ms 169928 KB Output is correct
56 Correct 114 ms 171196 KB Output is correct
57 Correct 123 ms 170068 KB Output is correct
58 Correct 113 ms 170460 KB Output is correct
59 Correct 112 ms 170632 KB Output is correct
60 Correct 117 ms 170652 KB Output is correct
61 Correct 112 ms 170692 KB Output is correct
62 Correct 139 ms 171460 KB Output is correct
63 Correct 220 ms 170820 KB Output is correct
64 Correct 245 ms 170796 KB Output is correct
65 Correct 332 ms 170944 KB Output is correct
66 Correct 432 ms 171076 KB Output is correct
67 Correct 467 ms 170864 KB Output is correct