Submission #977521

# Submission time Handle Problem Language Result Execution time Memory
977521 2024-05-08T06:10:28 Z Amaarsaa Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
595 ms 7632 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long ;
ll D[30005];
vector < ll > v[30005];
int main() {
//	freopen("moocast.in", "r", stdin);
//	freopen("moocast.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
	
	cin >> m >> n;
	
	priority_queue < pair < ll, ll >, vector < pair < ll, ll >> , greater < pair < ll, ll >> > pq;
	
	ll a[n + 2], b[n + 2];
	for (i = 0; i < n; i ++) {
		cin >> a[i] >> b[i];
		v[a[i]].push_back(b[i]);
	}
	for (i = 0; i <= m; i ++) D[i] = 1e18;
	D[a[0]] = 0;
	pq.push({0, a[0]});
	while(!pq.empty()) {
		x = pq.top().first;
		y = pq.top().second;
		pq.pop();
		if ( x != D[y]) continue;
		for ( ll X : v[y]) {
			s = y - X;
			dist = 1;
			while ( s >= 0) {
				
				if ( D[s] > D[y] + dist) {
					D[s] = D[y] + dist;
					pq.push({D[s], s});
				}
				dist ++;
				s -= X;
			}
			s = y + X;
			dist = 1;
			while ( s < m) {
				if ( D[s] > D[y] + dist) {
					D[s] = D[y] + dist;
					pq.push({D[s], s});
				}
				dist ++;
				s += X;
			}
		}
	}
	if ( D[a[1]] == 1e18) cout << -1 << endl;
	else cout << D[a[1]] << endl;
	
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:12:5: warning: unused variable 't' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |     ^
skyscraper.cpp:12:14: warning: unused variable 'ans' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |              ^~~
skyscraper.cpp:12:22: warning: unused variable 'sum' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                      ^~~
skyscraper.cpp:12:38: warning: unused variable 'r' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                      ^
skyscraper.cpp:12:41: warning: unused variable 'p' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                         ^
skyscraper.cpp:12:47: warning: unused variable 'j' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1112 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1368 KB Output is correct
26 Correct 4 ms 1116 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1500 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 2 ms 1372 KB Output is correct
32 Correct 1 ms 1624 KB Output is correct
33 Correct 2 ms 1628 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1340 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1368 KB Output is correct
26 Correct 3 ms 1112 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1500 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1628 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
35 Correct 5 ms 1884 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 5 ms 1884 KB Output is correct
38 Correct 7 ms 2140 KB Output is correct
39 Correct 6 ms 2200 KB Output is correct
40 Correct 6 ms 2140 KB Output is correct
41 Correct 6 ms 2140 KB Output is correct
42 Correct 42 ms 2012 KB Output is correct
43 Correct 41 ms 2012 KB Output is correct
44 Correct 41 ms 2136 KB Output is correct
45 Correct 6 ms 2396 KB Output is correct
46 Correct 6 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 2 ms 1124 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1124 KB Output is correct
20 Correct 4 ms 1116 KB Output is correct
21 Correct 1 ms 1128 KB Output is correct
22 Correct 1 ms 1124 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 1 ms 1376 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1500 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Correct 2 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 2 ms 1628 KB Output is correct
34 Correct 2 ms 1628 KB Output is correct
35 Correct 5 ms 1880 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 5 ms 1884 KB Output is correct
38 Correct 6 ms 2140 KB Output is correct
39 Correct 6 ms 2140 KB Output is correct
40 Correct 6 ms 2228 KB Output is correct
41 Correct 6 ms 2140 KB Output is correct
42 Correct 42 ms 1956 KB Output is correct
43 Correct 41 ms 2012 KB Output is correct
44 Correct 42 ms 2052 KB Output is correct
45 Correct 6 ms 2396 KB Output is correct
46 Correct 6 ms 2396 KB Output is correct
47 Correct 13 ms 3408 KB Output is correct
48 Correct 5 ms 2140 KB Output is correct
49 Correct 5 ms 2140 KB Output is correct
50 Correct 4 ms 1972 KB Output is correct
51 Correct 21 ms 4564 KB Output is correct
52 Correct 21 ms 3544 KB Output is correct
53 Correct 11 ms 3544 KB Output is correct
54 Correct 2 ms 1904 KB Output is correct
55 Correct 2 ms 1756 KB Output is correct
56 Correct 567 ms 3388 KB Output is correct
57 Correct 40 ms 6600 KB Output is correct
58 Correct 578 ms 2396 KB Output is correct
59 Correct 595 ms 2476 KB Output is correct
60 Correct 568 ms 2644 KB Output is correct
61 Correct 526 ms 2392 KB Output is correct
62 Correct 7 ms 2648 KB Output is correct
63 Correct 25 ms 4304 KB Output is correct
64 Correct 27 ms 6808 KB Output is correct
65 Correct 32 ms 7372 KB Output is correct
66 Correct 44 ms 6604 KB Output is correct
67 Correct 44 ms 7632 KB Output is correct