Submission #453279

# Submission time Handle Problem Language Result Execution time Memory
453279 2021-08-04T10:30:04 Z nonsensenonsense1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
465 ms 262148 KB
#include <cstdio>
#include <vector>
#include <deque>

struct node {
	int pos, dist;
	node *left, *right;
	bool vis;
	node(int pos_ = -1) {
		pos = pos_;
		left = right = 0;
		vis = false;
		dist = ~(1 << 31);
	}
};

const int N = 30000;
const int K = 180;
int n, m;
node g[K][N];
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].pos = j;
			if (i) {
				if (j >= i) g[i][j].left = g[i] + j - i;
				if (j + i < N) g[i][j].right = g[i] + j + i;
			}
		}
	}
	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 {
			node *r = new node(b);
			top[b].push_back(r);
			node *prev = r;
			for (int j = b - p; j >= 0; j -= p) {
				node *cur = new node(j);
				cur->right = prev;
				prev->left = cur;
				prev = cur;
			}
			prev = r;
			for (int j = b + p; j < N; j += p) {
				node *cur = new node(j);
				cur->left = prev;
				prev->right = cur;
				prev = cur;
			}
		}
	}
	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->left) go(cur, cur->left, 1);
				if (cur->right) go(cur, cur->right, 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:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d%d", &b, &p);
      |   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:89:14: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |  if (g[0][t].dist == ~(1 << 31)) printf("-1\n");
      |      ~~~~~~~~^~~~
skyscraper.cpp:75:22: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |  dq.push_back(g[0] + s);
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 116 ms 170048 KB Output is correct
2 Correct 116 ms 170000 KB Output is correct
3 Correct 118 ms 169964 KB Output is correct
4 Correct 114 ms 170036 KB Output is correct
5 Correct 115 ms 169952 KB Output is correct
6 Correct 118 ms 170016 KB Output is correct
7 Correct 119 ms 170048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 170072 KB Output is correct
2 Correct 122 ms 170044 KB Output is correct
3 Correct 126 ms 170044 KB Output is correct
4 Correct 118 ms 169956 KB Output is correct
5 Correct 121 ms 170048 KB Output is correct
6 Correct 115 ms 169952 KB Output is correct
7 Correct 114 ms 170052 KB Output is correct
8 Correct 115 ms 170040 KB Output is correct
9 Correct 120 ms 169936 KB Output is correct
10 Correct 136 ms 170088 KB Output is correct
11 Correct 178 ms 170112 KB Output is correct
12 Correct 121 ms 170080 KB Output is correct
13 Correct 117 ms 170004 KB Output is correct
14 Correct 171 ms 170008 KB Output is correct
15 Correct 167 ms 170052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 170044 KB Output is correct
2 Correct 117 ms 169924 KB Output is correct
3 Correct 113 ms 170032 KB Output is correct
4 Correct 114 ms 169952 KB Output is correct
5 Correct 118 ms 169988 KB Output is correct
6 Correct 119 ms 169960 KB Output is correct
7 Correct 117 ms 170012 KB Output is correct
8 Correct 125 ms 170000 KB Output is correct
9 Correct 126 ms 169936 KB Output is correct
10 Correct 139 ms 170032 KB Output is correct
11 Correct 173 ms 170052 KB Output is correct
12 Correct 118 ms 170060 KB Output is correct
13 Correct 115 ms 170060 KB Output is correct
14 Correct 173 ms 169992 KB Output is correct
15 Correct 171 ms 170100 KB Output is correct
16 Correct 115 ms 170684 KB Output is correct
17 Correct 161 ms 175116 KB Output is correct
18 Correct 116 ms 171596 KB Output is correct
19 Correct 116 ms 170964 KB Output is correct
20 Correct 117 ms 170056 KB Output is correct
21 Correct 119 ms 171936 KB Output is correct
22 Correct 118 ms 171240 KB Output is correct
23 Correct 126 ms 171776 KB Output is correct
24 Correct 139 ms 173256 KB Output is correct
25 Correct 121 ms 172748 KB Output is correct
26 Correct 132 ms 170200 KB Output is correct
27 Correct 120 ms 170564 KB Output is correct
28 Correct 139 ms 173692 KB Output is correct
29 Correct 143 ms 170040 KB Output is correct
30 Correct 133 ms 170052 KB Output is correct
31 Correct 135 ms 170112 KB Output is correct
32 Correct 123 ms 170052 KB Output is correct
33 Correct 183 ms 170052 KB Output is correct
34 Correct 174 ms 170096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 170004 KB Output is correct
2 Correct 116 ms 170044 KB Output is correct
3 Correct 120 ms 170032 KB Output is correct
4 Correct 116 ms 169936 KB Output is correct
5 Correct 116 ms 169944 KB Output is correct
6 Correct 123 ms 170044 KB Output is correct
7 Correct 118 ms 170048 KB Output is correct
8 Correct 115 ms 170028 KB Output is correct
9 Correct 125 ms 170044 KB Output is correct
10 Correct 144 ms 170056 KB Output is correct
11 Correct 189 ms 170108 KB Output is correct
12 Correct 122 ms 169960 KB Output is correct
13 Correct 118 ms 169976 KB Output is correct
14 Correct 173 ms 170008 KB Output is correct
15 Correct 166 ms 170060 KB Output is correct
16 Correct 117 ms 170676 KB Output is correct
17 Correct 167 ms 175172 KB Output is correct
18 Correct 121 ms 171604 KB Output is correct
19 Correct 117 ms 170948 KB Output is correct
20 Correct 121 ms 170108 KB Output is correct
21 Correct 117 ms 171932 KB Output is correct
22 Correct 133 ms 171204 KB Output is correct
23 Correct 127 ms 171624 KB Output is correct
24 Correct 138 ms 173356 KB Output is correct
25 Correct 133 ms 172704 KB Output is correct
26 Correct 122 ms 170232 KB Output is correct
27 Correct 120 ms 170568 KB Output is correct
28 Correct 134 ms 173656 KB Output is correct
29 Correct 141 ms 169984 KB Output is correct
30 Correct 132 ms 170048 KB Output is correct
31 Correct 125 ms 170000 KB Output is correct
32 Correct 122 ms 170024 KB Output is correct
33 Correct 185 ms 170088 KB Output is correct
34 Correct 179 ms 169992 KB Output is correct
35 Correct 370 ms 214604 KB Output is correct
36 Correct 163 ms 178328 KB Output is correct
37 Correct 432 ms 218980 KB Output is correct
38 Correct 429 ms 222404 KB Output is correct
39 Correct 395 ms 221864 KB Output is correct
40 Correct 422 ms 222020 KB Output is correct
41 Correct 413 ms 222452 KB Output is correct
42 Correct 132 ms 170804 KB Output is correct
43 Correct 128 ms 171056 KB Output is correct
44 Correct 126 ms 170600 KB Output is correct
45 Runtime error 205 ms 262148 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 138 ms 169992 KB Output is correct
2 Correct 141 ms 170052 KB Output is correct
3 Correct 115 ms 169932 KB Output is correct
4 Correct 124 ms 170028 KB Output is correct
5 Correct 117 ms 170008 KB Output is correct
6 Correct 118 ms 169964 KB Output is correct
7 Correct 116 ms 170008 KB Output is correct
8 Correct 118 ms 170076 KB Output is correct
9 Correct 130 ms 169960 KB Output is correct
10 Correct 139 ms 169996 KB Output is correct
11 Correct 195 ms 170100 KB Output is correct
12 Correct 125 ms 170052 KB Output is correct
13 Correct 119 ms 170048 KB Output is correct
14 Correct 181 ms 170056 KB Output is correct
15 Correct 183 ms 170104 KB Output is correct
16 Correct 138 ms 170560 KB Output is correct
17 Correct 171 ms 175084 KB Output is correct
18 Correct 121 ms 171716 KB Output is correct
19 Correct 132 ms 170968 KB Output is correct
20 Correct 120 ms 170092 KB Output is correct
21 Correct 121 ms 171968 KB Output is correct
22 Correct 127 ms 171192 KB Output is correct
23 Correct 132 ms 171596 KB Output is correct
24 Correct 138 ms 173324 KB Output is correct
25 Correct 141 ms 172628 KB Output is correct
26 Correct 124 ms 170188 KB Output is correct
27 Correct 138 ms 170572 KB Output is correct
28 Correct 137 ms 173636 KB Output is correct
29 Correct 146 ms 170064 KB Output is correct
30 Correct 144 ms 170044 KB Output is correct
31 Correct 141 ms 170044 KB Output is correct
32 Correct 133 ms 170044 KB Output is correct
33 Correct 194 ms 170048 KB Output is correct
34 Correct 175 ms 170104 KB Output is correct
35 Correct 377 ms 214384 KB Output is correct
36 Correct 161 ms 178244 KB Output is correct
37 Correct 400 ms 218916 KB Output is correct
38 Correct 415 ms 222368 KB Output is correct
39 Correct 408 ms 221916 KB Output is correct
40 Correct 465 ms 222028 KB Output is correct
41 Correct 402 ms 222452 KB Output is correct
42 Correct 125 ms 170744 KB Output is correct
43 Correct 124 ms 171076 KB Output is correct
44 Correct 124 ms 170588 KB Output is correct
45 Runtime error 237 ms 262148 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -