Submission #334955

# Submission time Handle Problem Language Result Execution time Memory
334955 2020-12-10T12:47:48 Z Saynaa Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
874 ms 10336 KB
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 2;
int n, m, b[MAXN], p[MAXN], dis[MAXN];
vector< int > adj[MAXN];
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i ++){
		cin >> b[i] >> p[i];
		adj[b[i]].push_back(p[i]);
	}
	fill(dis, dis + n, INT_MAX);
	dis[b[0]] = 0;
	priority_queue< pair< int, int> > q;
	q.push({0, b[0]});
	while( q.size() ){
		int v = q.top().second;
		q.pop();
		for(int i = 0; i < adj[v].size(); i ++){
			int u = adj[v][i];
			int x = 1;
			for(int i = v + u; i < n; i += u){
				if( dis[i] <= dis[v] + x){
					x ++;
					continue;
				}
				dis[i] = dis[v] + x;
				if( i != b[1]) q.push({-dis[i], i});
				x ++;	
			} 
			x = 1;
			for(int i = v - u; i >= 0; i -= u){
				if( dis[i] <= dis[v] + x){
					x ++;
					continue;
				}
				dis[i] = dis[v] + x;
				if( i != b[1]) q.push({-dis[i], i});
				x ++;
			}	
		}
	}
	cout << (dis[b[1]] != INT_MAX ? dis[b[1]] : -1 );
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0; i < adj[v].size(); i ++){
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
11 Correct 6 ms 7404 KB Output is correct
12 Correct 6 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 6 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7436 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 6 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 6 ms 7404 KB Output is correct
12 Correct 6 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 6 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 6 ms 7404 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 10 ms 7532 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7424 KB Output is correct
23 Correct 6 ms 7404 KB Output is correct
24 Correct 6 ms 7532 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 6 ms 7404 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 7 ms 7532 KB Output is correct
30 Correct 6 ms 7532 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 6 ms 7532 KB Output is correct
33 Correct 7 ms 7532 KB Output is correct
34 Correct 7 ms 7660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 6 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7424 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 6 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 6 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 6 ms 7404 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 10 ms 7532 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 7 ms 7404 KB Output is correct
23 Correct 7 ms 7404 KB Output is correct
24 Correct 7 ms 7532 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 6 ms 7404 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 7 ms 7532 KB Output is correct
30 Correct 6 ms 7532 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 6 ms 7532 KB Output is correct
33 Correct 7 ms 7532 KB Output is correct
34 Correct 8 ms 7660 KB Output is correct
35 Correct 12 ms 7916 KB Output is correct
36 Correct 7 ms 7532 KB Output is correct
37 Correct 12 ms 7916 KB Output is correct
38 Correct 15 ms 7916 KB Output is correct
39 Correct 15 ms 7916 KB Output is correct
40 Correct 15 ms 7916 KB Output is correct
41 Correct 15 ms 7916 KB Output is correct
42 Correct 11 ms 7916 KB Output is correct
43 Correct 10 ms 7916 KB Output is correct
44 Correct 68 ms 7916 KB Output is correct
45 Correct 15 ms 7916 KB Output is correct
46 Correct 14 ms 7916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 7 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 6 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 6 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 10 ms 7532 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 6 ms 7404 KB Output is correct
24 Correct 6 ms 7532 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 6 ms 7424 KB Output is correct
27 Correct 6 ms 7404 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 7 ms 7532 KB Output is correct
30 Correct 6 ms 7532 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 6 ms 7532 KB Output is correct
33 Correct 9 ms 7532 KB Output is correct
34 Correct 7 ms 7660 KB Output is correct
35 Correct 12 ms 7916 KB Output is correct
36 Correct 7 ms 7532 KB Output is correct
37 Correct 12 ms 7916 KB Output is correct
38 Correct 15 ms 7916 KB Output is correct
39 Correct 15 ms 8044 KB Output is correct
40 Correct 15 ms 7916 KB Output is correct
41 Correct 15 ms 7916 KB Output is correct
42 Correct 10 ms 7916 KB Output is correct
43 Correct 10 ms 7916 KB Output is correct
44 Correct 72 ms 8064 KB Output is correct
45 Correct 15 ms 7916 KB Output is correct
46 Correct 14 ms 7916 KB Output is correct
47 Correct 30 ms 8680 KB Output is correct
48 Correct 12 ms 8172 KB Output is correct
49 Correct 11 ms 8044 KB Output is correct
50 Correct 10 ms 7916 KB Output is correct
51 Correct 39 ms 9444 KB Output is correct
52 Correct 34 ms 8936 KB Output is correct
53 Correct 19 ms 8556 KB Output is correct
54 Correct 7 ms 7788 KB Output is correct
55 Correct 7 ms 7788 KB Output is correct
56 Correct 871 ms 9072 KB Output is correct
57 Correct 95 ms 9824 KB Output is correct
58 Correct 874 ms 8216 KB Output is correct
59 Correct 13 ms 8172 KB Output is correct
60 Correct 12 ms 8172 KB Output is correct
61 Correct 13 ms 8428 KB Output is correct
62 Correct 17 ms 9068 KB Output is correct
63 Correct 31 ms 9320 KB Output is correct
64 Correct 31 ms 9316 KB Output is correct
65 Correct 36 ms 9324 KB Output is correct
66 Correct 64 ms 10336 KB Output is correct
67 Correct 64 ms 10336 KB Output is correct