Submission #907158

# Submission time Handle Problem Language Result Execution time Memory
907158 2024-01-15T07:48:46 Z yellowtoad Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 109604 KB
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define f first
#define s second
using namespace std;

int n, m, cnt, st, ed, dist[10000010], vis[10000010];
map<pair<int,int>,int> mp;
vector<vector<pair<int,int>>> edge;
deque<int> q;

int main() {
	cin >> n >> m;
	cnt = n-1;
	for (int i = 0; i < n; i++) edge.push_back({});
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		if (i == 1) st = u;
		if (i == 2) ed = u;
		if (!mp[{u,v}]) {
			for (int j = u%v; j < n; j += v) {
				mp[{j,v}] = ++cnt;
				edge.push_back({{j,0}});
				if (j != u%v) {
					edge[cnt].push_back({cnt-1,1});
					edge[cnt-1].push_back({cnt,1});
				}
			}
		}
		edge[u].push_back({mp[{u,v}],0});
	}
	for (int i = 0; i <= cnt; i++) dist[i] = 1e9;
	q.push_back(st);
	dist[st] = 0;
	while (q.size()) {
		int u = q.front();
		q.pop_front();
		if (vis[u]) continue;
		vis[u] = 1;
		for (int i = 0; i < edge[u].size(); i++) {
			if (dist[edge[u][i].f] > dist[u]+edge[u][i].s) {
				dist[edge[u][i].f] = dist[u]+edge[u][i].s;
				if (edge[u][i].s) q.push_back(edge[u][i].f);
				else q.push_front(edge[u][i].f);
			}
		}
	}
	if (dist[ed] == 1e9) cout << -1 << endl;
	else cout << dist[ed] << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for (int i = 0; i < edge[u].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 4 ms 5212 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 4 ms 5212 KB Output is correct
15 Correct 5 ms 5212 KB Output is correct
16 Correct 3 ms 3164 KB Output is correct
17 Correct 7 ms 6552 KB Output is correct
18 Correct 5 ms 5276 KB Output is correct
19 Correct 3 ms 5216 KB Output is correct
20 Correct 2 ms 2912 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 3 ms 5288 KB Output is correct
23 Correct 4 ms 5468 KB Output is correct
24 Correct 7 ms 6296 KB Output is correct
25 Correct 5 ms 5528 KB Output is correct
26 Correct 4 ms 5528 KB Output is correct
27 Correct 4 ms 5528 KB Output is correct
28 Correct 11 ms 7700 KB Output is correct
29 Correct 30 ms 12988 KB Output is correct
30 Correct 7 ms 6932 KB Output is correct
31 Correct 14 ms 8976 KB Output is correct
32 Correct 10 ms 7696 KB Output is correct
33 Correct 79 ms 21004 KB Output is correct
34 Correct 82 ms 21024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2496 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 3 ms 2908 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 4 ms 5212 KB Output is correct
15 Correct 4 ms 5212 KB Output is correct
16 Correct 5 ms 2904 KB Output is correct
17 Correct 8 ms 6552 KB Output is correct
18 Correct 4 ms 5272 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 3 ms 2656 KB Output is correct
22 Correct 3 ms 5464 KB Output is correct
23 Correct 4 ms 5468 KB Output is correct
24 Correct 7 ms 6296 KB Output is correct
25 Correct 5 ms 5528 KB Output is correct
26 Correct 4 ms 5528 KB Output is correct
27 Correct 4 ms 5644 KB Output is correct
28 Correct 10 ms 7700 KB Output is correct
29 Correct 27 ms 12836 KB Output is correct
30 Correct 8 ms 6932 KB Output is correct
31 Correct 18 ms 8976 KB Output is correct
32 Correct 10 ms 7816 KB Output is correct
33 Correct 93 ms 20992 KB Output is correct
34 Correct 98 ms 20760 KB Output is correct
35 Correct 89 ms 18888 KB Output is correct
36 Correct 11 ms 6928 KB Output is correct
37 Correct 214 ms 29756 KB Output is correct
38 Correct 163 ms 27512 KB Output is correct
39 Correct 207 ms 27304 KB Output is correct
40 Correct 153 ms 27636 KB Output is correct
41 Correct 161 ms 28400 KB Output is correct
42 Correct 15 ms 6296 KB Output is correct
43 Correct 16 ms 6040 KB Output is correct
44 Correct 12 ms 3288 KB Output is correct
45 Correct 674 ms 70132 KB Output is correct
46 Correct 691 ms 70256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2548 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 6 ms 5208 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 2904 KB Output is correct
17 Correct 8 ms 6552 KB Output is correct
18 Correct 4 ms 5268 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 2904 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 4 ms 5320 KB Output is correct
23 Correct 5 ms 5464 KB Output is correct
24 Correct 7 ms 6292 KB Output is correct
25 Correct 5 ms 5524 KB Output is correct
26 Correct 5 ms 5524 KB Output is correct
27 Correct 4 ms 5528 KB Output is correct
28 Correct 11 ms 7696 KB Output is correct
29 Correct 42 ms 12804 KB Output is correct
30 Correct 8 ms 7184 KB Output is correct
31 Correct 24 ms 9088 KB Output is correct
32 Correct 10 ms 7700 KB Output is correct
33 Correct 104 ms 21012 KB Output is correct
34 Correct 100 ms 20992 KB Output is correct
35 Correct 95 ms 18420 KB Output is correct
36 Correct 12 ms 6932 KB Output is correct
37 Correct 163 ms 29424 KB Output is correct
38 Correct 185 ms 28472 KB Output is correct
39 Correct 188 ms 27900 KB Output is correct
40 Correct 183 ms 27728 KB Output is correct
41 Correct 194 ms 26900 KB Output is correct
42 Correct 14 ms 6296 KB Output is correct
43 Correct 20 ms 6040 KB Output is correct
44 Correct 12 ms 3284 KB Output is correct
45 Correct 769 ms 70636 KB Output is correct
46 Correct 856 ms 70220 KB Output is correct
47 Execution timed out 1093 ms 109604 KB Time limit exceeded
48 Halted 0 ms 0 KB -