Submission #105293

# Submission time Handle Problem Language Result Execution time Memory
105293 2019-04-11T06:53:43 Z DystoriaX Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
929 ms 24576 KB
#include <bits/stdc++.h>

#define eb emplace_back

using namespace std;

int n, m;
int b[30010], p[30010];
vector<int> doge[30010];
const int sq = sqrt(30000) + 3;
const int INF = 1e9;
int dist[sq + 1][30010];
priority_queue<tuple<int, int, int> > pq;

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++){
		scanf("%d%d", &b[i], &p[i]);
		doge[b[i]].eb(p[i]);
	}

	for(int i = 0; i < n; i++)
		for(int j = 0; j <= sq; j++)
			dist[j][i] = INF;
	dist[p[0] > sq ? 0 : p[0]][b[0]] = 0;
	pq.push({0, b[0], p[0]});

	while(!pq.empty()){
		int d, pos, pow;
		tie(d, pos, pow) = pq.top(); pq.pop();
		d = -d;

		if(d != dist[pow > sq ? 0 : pow][pos]) continue;

		if(pow != 0) doge[pos].eb(pow);
		for(auto v : doge[pos]){
			int pow = v;
			if(pow <= sq){
				if(pos + pow < n && dist[pow][pos + pow] > d + 1){
					dist[pow][pos + pow] = d + 1;
					pq.push({-dist[pow][pos + pow], pos + pow, pow});
				}
				if(pos - pow >= 0 && dist[pow][pos - pow] > d + 1){
					dist[pow][pos - pow] = d + 1;
					pq.push({-dist[pow][pos - pow], pos - pow, pow});
				}
			} else {
				int k = 1;
				while(pos + k * pow < n){
					if(dist[0][pos + k * pow] > d + k){
						dist[0][pos + k * pow] = d + k;
						pq.push({-dist[0][pos + k * pow], pos + k * pow, 0});
					}
					k++;
				}

				k = 1;
				while(pos - k * pow >= 0){
					if(dist[0][pos - k * pow] > d + k){
						dist[0][pos - k * pow] = d + k;
						pq.push({-dist[0][pos - k * pow], pos - k * pow, 0});
					}
					k++;
				}
			}
		}
		doge[pos].clear();
	}

	int ans = INF;
	for(int i = 0; i <= sq; i++) ans = min(ans, dist[i][b[1]]);

	printf("%d\n", ans == INF ? -1 : ans);

	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &b[i], &p[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1792 KB Output is correct
2 Correct 3 ms 1792 KB Output is correct
3 Correct 4 ms 1792 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1792 KB Output is correct
2 Correct 3 ms 1792 KB Output is correct
3 Correct 3 ms 1792 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 8 ms 1792 KB Output is correct
7 Correct 4 ms 1792 KB Output is correct
8 Correct 4 ms 1836 KB Output is correct
9 Correct 3 ms 1792 KB Output is correct
10 Correct 3 ms 1792 KB Output is correct
11 Correct 5 ms 1892 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 4 ms 1792 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 4 ms 1964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 4 ms 1764 KB Output is correct
3 Correct 4 ms 1792 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 4 ms 1792 KB Output is correct
7 Correct 4 ms 1792 KB Output is correct
8 Correct 3 ms 1864 KB Output is correct
9 Correct 4 ms 1792 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 5 ms 1920 KB Output is correct
13 Correct 5 ms 1920 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 3 ms 1920 KB Output is correct
17 Correct 8 ms 2304 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 2048 KB Output is correct
22 Correct 6 ms 3072 KB Output is correct
23 Correct 7 ms 2944 KB Output is correct
24 Correct 9 ms 3200 KB Output is correct
25 Correct 7 ms 3200 KB Output is correct
26 Correct 7 ms 3328 KB Output is correct
27 Correct 5 ms 3200 KB Output is correct
28 Correct 7 ms 3200 KB Output is correct
29 Correct 15 ms 3200 KB Output is correct
30 Correct 7 ms 3200 KB Output is correct
31 Correct 9 ms 3200 KB Output is correct
32 Correct 11 ms 3200 KB Output is correct
33 Correct 21 ms 3328 KB Output is correct
34 Correct 21 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 3 ms 1764 KB Output is correct
3 Correct 4 ms 1768 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
8 Correct 4 ms 1792 KB Output is correct
9 Correct 4 ms 1792 KB Output is correct
10 Correct 4 ms 1788 KB Output is correct
11 Correct 4 ms 1920 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 3 ms 1920 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 4 ms 1920 KB Output is correct
16 Correct 3 ms 1920 KB Output is correct
17 Correct 7 ms 2396 KB Output is correct
18 Correct 5 ms 2944 KB Output is correct
19 Correct 4 ms 3200 KB Output is correct
20 Correct 7 ms 3200 KB Output is correct
21 Correct 4 ms 2048 KB Output is correct
22 Correct 6 ms 3072 KB Output is correct
23 Correct 6 ms 2944 KB Output is correct
24 Correct 7 ms 3200 KB Output is correct
25 Correct 6 ms 3200 KB Output is correct
26 Correct 7 ms 3328 KB Output is correct
27 Correct 5 ms 3200 KB Output is correct
28 Correct 7 ms 3200 KB Output is correct
29 Correct 12 ms 3200 KB Output is correct
30 Correct 6 ms 3200 KB Output is correct
31 Correct 8 ms 3196 KB Output is correct
32 Correct 9 ms 3200 KB Output is correct
33 Correct 25 ms 3328 KB Output is correct
34 Correct 21 ms 3328 KB Output is correct
35 Correct 22 ms 3328 KB Output is correct
36 Correct 8 ms 2560 KB Output is correct
37 Correct 42 ms 3840 KB Output is correct
38 Correct 31 ms 3840 KB Output is correct
39 Correct 29 ms 3840 KB Output is correct
40 Correct 39 ms 3840 KB Output is correct
41 Correct 25 ms 3840 KB Output is correct
42 Correct 12 ms 3584 KB Output is correct
43 Correct 15 ms 3684 KB Output is correct
44 Correct 12 ms 3584 KB Output is correct
45 Correct 78 ms 4160 KB Output is correct
46 Correct 72 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 4 ms 1792 KB Output is correct
3 Correct 4 ms 1664 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 4 ms 1792 KB Output is correct
8 Correct 3 ms 1792 KB Output is correct
9 Correct 4 ms 1792 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 5 ms 1920 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 7 ms 2432 KB Output is correct
18 Correct 7 ms 3072 KB Output is correct
19 Correct 5 ms 3200 KB Output is correct
20 Correct 6 ms 3200 KB Output is correct
21 Correct 4 ms 2048 KB Output is correct
22 Correct 5 ms 3072 KB Output is correct
23 Correct 7 ms 2944 KB Output is correct
24 Correct 8 ms 3200 KB Output is correct
25 Correct 9 ms 3328 KB Output is correct
26 Correct 7 ms 3328 KB Output is correct
27 Correct 6 ms 3200 KB Output is correct
28 Correct 9 ms 3200 KB Output is correct
29 Correct 15 ms 3200 KB Output is correct
30 Correct 7 ms 3200 KB Output is correct
31 Correct 9 ms 3328 KB Output is correct
32 Correct 9 ms 3200 KB Output is correct
33 Correct 25 ms 3328 KB Output is correct
34 Correct 21 ms 3328 KB Output is correct
35 Correct 30 ms 3300 KB Output is correct
36 Correct 10 ms 2688 KB Output is correct
37 Correct 41 ms 3712 KB Output is correct
38 Correct 29 ms 3840 KB Output is correct
39 Correct 37 ms 3832 KB Output is correct
40 Correct 31 ms 3840 KB Output is correct
41 Correct 29 ms 3840 KB Output is correct
42 Correct 11 ms 3676 KB Output is correct
43 Correct 15 ms 3584 KB Output is correct
44 Correct 16 ms 3704 KB Output is correct
45 Correct 72 ms 4160 KB Output is correct
46 Correct 78 ms 4160 KB Output is correct
47 Correct 126 ms 11320 KB Output is correct
48 Correct 36 ms 18424 KB Output is correct
49 Correct 35 ms 19896 KB Output is correct
50 Correct 33 ms 21496 KB Output is correct
51 Correct 105 ms 23284 KB Output is correct
52 Correct 112 ms 23304 KB Output is correct
53 Correct 70 ms 23032 KB Output is correct
54 Correct 40 ms 22264 KB Output is correct
55 Correct 34 ms 22392 KB Output is correct
56 Correct 45 ms 23036 KB Output is correct
57 Correct 108 ms 22748 KB Output is correct
58 Correct 41 ms 23032 KB Output is correct
59 Correct 43 ms 23032 KB Output is correct
60 Correct 57 ms 23160 KB Output is correct
61 Correct 55 ms 23164 KB Output is correct
62 Correct 62 ms 23032 KB Output is correct
63 Correct 51 ms 23920 KB Output is correct
64 Correct 56 ms 23920 KB Output is correct
65 Correct 340 ms 24040 KB Output is correct
66 Correct 929 ms 24560 KB Output is correct
67 Correct 865 ms 24576 KB Output is correct