Submission #907354

# Submission time Handle Problem Language Result Execution time Memory
907354 2024-01-15T12:09:50 Z yellowtoad Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
121 ms 66984 KB
#include <iostream>
#include <vector>
#include <queue>
#define f first
#define s second
using namespace std;
 
const short LIM = 174; 
short n, m, st, ed;
unsigned short dist[6000010];
bool vis[6000010], hv[30010];
int cnt, b[30010][180];
pair<short,short> a[30010];
vector<vector<pair<int,unsigned short>>> edge;
deque<int> q;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	cnt = n-1;
	for (short i = 0; i < n; i++) edge.push_back({});
	for (short i = 1; i <= m; i++) {
		cin >> a[i].f >> a[i].s;
		hv[a[i].f] = 1;
	}
	for (short i = 1; i <= m; i++) {
		short u = a[i].f, v = a[i].s;
		if (i == 1) st = u;
		if (i == 2) ed = u;
		if (v <= LIM) {
			if (!b[u][v]) {
				for (int j = u%v; j < n; j += v) {
					b[j][v] = ++cnt;
					edge.push_back({});
					if (hv[j]) edge[cnt].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({b[u][v],0});
		} else {
			for (int j = u%v; j < n; j += v) {
				++cnt;
				edge.push_back({});
				if (hv[j]) edge[cnt].push_back({j,0});
				if (j == u) edge[u].push_back({cnt,0});
				if (j != u%v) {
					edge[cnt].push_back({cnt-1,1});
					edge[cnt-1].push_back({cnt,1});
				}
			}
		}
	}
	for (int i = 0; i <= cnt; i++) dist[i] = 65535;
	q.push_back(st);
	dist[st] = 0;
	while (q.size()) {
		int u = q.front();
		q.pop_front();
		if (vis[u]) continue;
		vis[u] = 1;
		if (u == ed) {
			cout << dist[ed] << endl;
			return 0;
		}
		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);
			}
		}
	}
	cout << -1 << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, short unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for (int i = 0; i < edge[u].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4596 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 6040 KB Output is correct
18 Correct 2 ms 6040 KB Output is correct
19 Correct 2 ms 6236 KB Output is correct
20 Correct 2 ms 6744 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 3 ms 5976 KB Output is correct
24 Correct 3 ms 6804 KB Output is correct
25 Correct 3 ms 6552 KB Output is correct
26 Correct 3 ms 7064 KB Output is correct
27 Correct 2 ms 7064 KB Output is correct
28 Correct 5 ms 8408 KB Output is correct
29 Correct 12 ms 10000 KB Output is correct
30 Correct 3 ms 7700 KB Output is correct
31 Correct 5 ms 8464 KB Output is correct
32 Correct 6 ms 8208 KB Output is correct
33 Correct 14 ms 13320 KB Output is correct
34 Correct 14 ms 13320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 7004 KB Output is correct
15 Correct 3 ms 7004 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 4 ms 5952 KB Output is correct
18 Correct 3 ms 6296 KB Output is correct
19 Correct 2 ms 6236 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
23 Correct 3 ms 5980 KB Output is correct
24 Correct 4 ms 6552 KB Output is correct
25 Correct 3 ms 6356 KB Output is correct
26 Correct 3 ms 7064 KB Output is correct
27 Correct 3 ms 7064 KB Output is correct
28 Correct 5 ms 8212 KB Output is correct
29 Correct 8 ms 9996 KB Output is correct
30 Correct 3 ms 7700 KB Output is correct
31 Correct 5 ms 8464 KB Output is correct
32 Correct 4 ms 7956 KB Output is correct
33 Correct 15 ms 13324 KB Output is correct
34 Correct 14 ms 13324 KB Output is correct
35 Correct 17 ms 12552 KB Output is correct
36 Correct 4 ms 7956 KB Output is correct
37 Correct 25 ms 18304 KB Output is correct
38 Correct 28 ms 19208 KB Output is correct
39 Correct 25 ms 18984 KB Output is correct
40 Correct 25 ms 18440 KB Output is correct
41 Correct 27 ms 17984 KB Output is correct
42 Correct 7 ms 7576 KB Output is correct
43 Correct 6 ms 7576 KB Output is correct
44 Correct 5 ms 7124 KB Output is correct
45 Correct 90 ms 34032 KB Output is correct
46 Correct 67 ms 34036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 5 ms 6040 KB Output is correct
18 Correct 3 ms 6040 KB Output is correct
19 Correct 2 ms 6236 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 4 ms 6552 KB Output is correct
25 Correct 3 ms 6552 KB Output is correct
26 Correct 3 ms 7064 KB Output is correct
27 Correct 2 ms 7060 KB Output is correct
28 Correct 5 ms 8208 KB Output is correct
29 Correct 8 ms 9996 KB Output is correct
30 Correct 4 ms 7696 KB Output is correct
31 Correct 6 ms 8464 KB Output is correct
32 Correct 4 ms 7956 KB Output is correct
33 Correct 14 ms 13320 KB Output is correct
34 Correct 13 ms 13324 KB Output is correct
35 Correct 18 ms 12576 KB Output is correct
36 Correct 4 ms 7952 KB Output is correct
37 Correct 29 ms 19920 KB Output is correct
38 Correct 29 ms 18844 KB Output is correct
39 Correct 25 ms 18312 KB Output is correct
40 Correct 28 ms 17408 KB Output is correct
41 Correct 27 ms 17660 KB Output is correct
42 Correct 6 ms 7576 KB Output is correct
43 Correct 5 ms 7576 KB Output is correct
44 Correct 5 ms 7184 KB Output is correct
45 Correct 106 ms 33976 KB Output is correct
46 Correct 68 ms 34732 KB Output is correct
47 Correct 121 ms 66984 KB Output is correct
48 Correct 42 ms 36800 KB Output is correct
49 Correct 29 ms 33740 KB Output is correct
50 Correct 28 ms 35412 KB Output is correct
51 Correct 61 ms 46624 KB Output is correct
52 Correct 71 ms 50104 KB Output is correct
53 Correct 20 ms 31952 KB Output is correct
54 Correct 10 ms 27348 KB Output is correct
55 Correct 12 ms 29392 KB Output is correct
56 Correct 17 ms 28868 KB Output is correct
57 Correct 63 ms 49944 KB Output is correct
58 Correct 15 ms 30504 KB Output is correct
59 Correct 18 ms 31696 KB Output is correct
60 Correct 25 ms 35532 KB Output is correct
61 Correct 21 ms 33744 KB Output is correct
62 Incorrect 98 ms 60856 KB Output isn't correct
63 Halted 0 ms 0 KB -