Submission #453329

# Submission time Handle Problem Language Result Execution time Memory
453329 2021-08-04T10:46:29 Z nonsensenonsense1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
22 / 100
241 ms 170192 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 - 1] ? cur - cur->step : cur - 1, 1);
				if (cur->pos + cur->step < N) go(cur, cur >= g[0] && cur <= g[K - 1] ? 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 103 ms 170136 KB Output is correct
2 Correct 106 ms 169972 KB Output is correct
3 Correct 101 ms 170096 KB Output is correct
4 Correct 107 ms 170048 KB Output is correct
5 Correct 104 ms 170008 KB Output is correct
6 Correct 106 ms 170028 KB Output is correct
7 Correct 106 ms 170012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 169980 KB Output is correct
2 Correct 109 ms 169980 KB Output is correct
3 Correct 103 ms 170044 KB Output is correct
4 Correct 119 ms 170020 KB Output is correct
5 Correct 108 ms 170092 KB Output is correct
6 Correct 103 ms 170052 KB Output is correct
7 Correct 108 ms 169952 KB Output is correct
8 Correct 119 ms 169924 KB Output is correct
9 Correct 119 ms 170040 KB Output is correct
10 Correct 130 ms 170060 KB Output is correct
11 Correct 198 ms 170036 KB Output is correct
12 Correct 109 ms 170004 KB Output is correct
13 Correct 110 ms 169960 KB Output is correct
14 Correct 153 ms 170100 KB Output is correct
15 Correct 150 ms 169980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 169944 KB Output is correct
2 Correct 107 ms 169996 KB Output is correct
3 Correct 105 ms 169940 KB Output is correct
4 Correct 106 ms 170052 KB Output is correct
5 Correct 112 ms 170028 KB Output is correct
6 Correct 118 ms 169980 KB Output is correct
7 Correct 127 ms 170016 KB Output is correct
8 Correct 120 ms 169964 KB Output is correct
9 Correct 126 ms 169980 KB Output is correct
10 Correct 143 ms 170040 KB Output is correct
11 Correct 163 ms 170112 KB Output is correct
12 Correct 112 ms 170052 KB Output is correct
13 Correct 101 ms 170192 KB Output is correct
14 Correct 189 ms 170100 KB Output is correct
15 Correct 156 ms 170092 KB Output is correct
16 Incorrect 210 ms 170072 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 170052 KB Output is correct
2 Correct 99 ms 169976 KB Output is correct
3 Correct 113 ms 170060 KB Output is correct
4 Correct 118 ms 170124 KB Output is correct
5 Correct 114 ms 170044 KB Output is correct
6 Correct 109 ms 170044 KB Output is correct
7 Correct 124 ms 169924 KB Output is correct
8 Correct 103 ms 169928 KB Output is correct
9 Correct 105 ms 170052 KB Output is correct
10 Correct 127 ms 170040 KB Output is correct
11 Correct 162 ms 170000 KB Output is correct
12 Correct 123 ms 170024 KB Output is correct
13 Correct 108 ms 169996 KB Output is correct
14 Correct 167 ms 170052 KB Output is correct
15 Correct 200 ms 170100 KB Output is correct
16 Incorrect 241 ms 170012 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 169992 KB Output is correct
2 Correct 108 ms 169968 KB Output is correct
3 Correct 114 ms 170028 KB Output is correct
4 Correct 106 ms 169992 KB Output is correct
5 Correct 101 ms 170044 KB Output is correct
6 Correct 215 ms 170016 KB Output is correct
7 Correct 107 ms 170044 KB Output is correct
8 Correct 109 ms 169988 KB Output is correct
9 Correct 114 ms 169964 KB Output is correct
10 Correct 128 ms 170048 KB Output is correct
11 Correct 161 ms 170104 KB Output is correct
12 Correct 103 ms 170052 KB Output is correct
13 Correct 105 ms 170004 KB Output is correct
14 Correct 157 ms 170048 KB Output is correct
15 Correct 150 ms 170104 KB Output is correct
16 Incorrect 198 ms 169972 KB Output isn't correct
17 Halted 0 ms 0 KB -