Submission #330582

# Submission time Handle Problem Language Result Execution time Memory
330582 2020-11-25T20:35:19 Z minoum Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
835 ms 3944 KB
#include<bits/stdc++.h>
///#pragma GCC optimization ("unroll-loops")
 
using namespace std;
typedef long long int ll;
 
const int MAXN = 3e4+1, inf = INT_MAX / 2;
int n, m, b[MAXN], p[MAXN], d[MAXN], tmp, t = 0;
vector <int> ps[MAXN];
priority_queue <pair<int,int>> q;
 
int main()
{
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	cin >> n >> m;
	scanf("%d", &n); scanf("%d", &m);
	for(int i = 0; i < m; i++){
//		cin >> bb >> pp;
		scanf("%d", b+i); scanf("%d", p+i);
		ps[b[i]].push_back({p[i]});
	}
	for(int i = 0; i < n; i++) d[i] = inf;
	d[b[0]] = 0;
	q.push({0, b[0]});
	while(!q.empty()){
		int u = q.top().second, dd = -q.top().second; q.pop();
		if(d[u] < dd) continue;
		if(u == b[1] || d[u] >= inf) break;
		for(int k: ps[u]){
			t = 1;
			for(int i = u - k; i >= 0; i -= k){
				if(d[i] > d[u] + t){
					d[i] = d[u] + t;
					q.push({-d[i], i});
				}
				t++;
			}
			t = 1;
			for(int i = u + k; i < n; i += k){
				if(d[i] > d[u] + t){
					d[i] = d[u] + t;
					q.push({-d[i], i});
				}
				t++;
			}
		}
	}
//	cout << ((d[b[1]] >= inf)?-1:d[b[1]]);
	if(d[b[1]] >= inf) printf("%d", -1);
	else printf("%d", d[b[1]]);
	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]
   16 |  scanf("%d", &n); scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
skyscraper.cpp:16:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d", &n); scanf("%d", &m);
      |                   ~~~~~^~~~~~~~~~
skyscraper.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%d", b+i); scanf("%d", p+i);
      |   ~~~~~^~~~~~~~~~~
skyscraper.cpp:19:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%d", b+i); scanf("%d", p+i);
      |                     ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 3 ms 1132 KB Output is correct
32 Correct 2 ms 1132 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 63 ms 1260 KB Output is correct
32 Correct 2 ms 1260 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 2 ms 1260 KB Output is correct
35 Correct 9 ms 1772 KB Output is correct
36 Correct 2 ms 1132 KB Output is correct
37 Correct 7 ms 1644 KB Output is correct
38 Correct 11 ms 1900 KB Output is correct
39 Correct 10 ms 1772 KB Output is correct
40 Correct 10 ms 1900 KB Output is correct
41 Correct 11 ms 1900 KB Output is correct
42 Correct 8 ms 1772 KB Output is correct
43 Correct 8 ms 1772 KB Output is correct
44 Correct 66 ms 1796 KB Output is correct
45 Correct 11 ms 1772 KB Output is correct
46 Correct 10 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 2 ms 1152 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 2 ms 1260 KB Output is correct
35 Correct 9 ms 1772 KB Output is correct
36 Correct 2 ms 1132 KB Output is correct
37 Correct 7 ms 1644 KB Output is correct
38 Correct 11 ms 1900 KB Output is correct
39 Correct 9 ms 1772 KB Output is correct
40 Correct 10 ms 1900 KB Output is correct
41 Correct 10 ms 1900 KB Output is correct
42 Correct 8 ms 1772 KB Output is correct
43 Correct 8 ms 1772 KB Output is correct
44 Correct 64 ms 1660 KB Output is correct
45 Correct 11 ms 1772 KB Output is correct
46 Correct 10 ms 1772 KB Output is correct
47 Correct 11 ms 2540 KB Output is correct
48 Correct 9 ms 2048 KB Output is correct
49 Correct 8 ms 2028 KB Output is correct
50 Correct 7 ms 1772 KB Output is correct
51 Correct 21 ms 3560 KB Output is correct
52 Correct 23 ms 2888 KB Output is correct
53 Correct 12 ms 2540 KB Output is correct
54 Correct 2 ms 1388 KB Output is correct
55 Correct 3 ms 1388 KB Output is correct
56 Correct 835 ms 2924 KB Output is correct
57 Correct 4 ms 2412 KB Output is correct
58 Correct 783 ms 1900 KB Output is correct
59 Correct 10 ms 2028 KB Output is correct
60 Correct 10 ms 1900 KB Output is correct
61 Correct 10 ms 2028 KB Output is correct
62 Correct 14 ms 2668 KB Output is correct
63 Correct 27 ms 3052 KB Output is correct
64 Correct 26 ms 2924 KB Output is correct
65 Correct 31 ms 3048 KB Output is correct
66 Correct 55 ms 3944 KB Output is correct
67 Correct 43 ms 3940 KB Output is correct