Submission #41517

# Submission time Handle Problem Language Result Execution time Memory
41517 2018-02-18T03:08:00 Z wzy Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
342 ms 153100 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
vector<pii> adj[300005];
int  n, m;
set<int> p[300005];
long long d[300005];

int32_t main(){
	scanf("%lld%lld" ,  &n,  &m);
	int target = -1;
	int start = 0;
	for(int i = 0 ; i <m ; i ++){
		int  b, x;
		scanf("%lld%lld" , &b , &x);
		p[b].insert(x);
		if(i == 1){
			target = b;
		}
		if(i == 0){
			start = b;
		}
	}
	for(int i = 0 ; i < n; i++){
		for(auto t : p[i]){
			for(int j = 1  ; j*t + i < n ; j++){
				adj[i].pb(pii(j , j*t+i));
				if(p[j*t + i].count(t)) break;
			}
			for(int j = 1 ; i - j*t >=0 ; j++){
				adj[i].pb(pii(j , i-j*t));
				if(p[i - j*t].count(t)) break;
			}	
		}
	}
	priority_queue<pii , vector<pii> , greater<pii> > pq;
	pq.push(pii(0 , start));
	for(int i = 0 ; i< n; i++) d[i] = (long long) 1e18;
	d[start] = 0;
	while(!pq.empty()){
		pii u = pq.top();
		pq.pop();
		if(d[u.S] < u.F) continue;
		for(int i = 0 ; i < adj[u.S].size() ; i++){
			pii v = adj[u.S][i];
			if(d[v.S] > u.F + v.F){
				d[v.S] = u.F + v.F;
				pq.push(pii(u.F + v.F , v.S));
			}
		}
	}
	if(target == -1) printf("%lld\n" , -1LL);
	else{
	if(d[target] == (int) 1e18) printf("%lld\n" , -1LL);
	else{
		printf("%lld\n" , d[target]);
	}
}
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < adj[u.S].size() ; i++){
                     ^
skyscraper.cpp:15:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld" ,  &n,  &m);
                              ^
skyscraper.cpp:20:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld" , &b , &x);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 25 ms 21368 KB Output is correct
2 Correct 19 ms 21476 KB Output is correct
3 Correct 21 ms 21584 KB Output is correct
4 Correct 21 ms 21692 KB Output is correct
5 Correct 21 ms 21748 KB Output is correct
6 Correct 19 ms 21868 KB Output is correct
7 Correct 19 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 21908 KB Output is correct
2 Correct 20 ms 21908 KB Output is correct
3 Correct 21 ms 21908 KB Output is correct
4 Correct 20 ms 21908 KB Output is correct
5 Correct 21 ms 21916 KB Output is correct
6 Correct 21 ms 21916 KB Output is correct
7 Correct 21 ms 21916 KB Output is correct
8 Correct 19 ms 21916 KB Output is correct
9 Correct 18 ms 21928 KB Output is correct
10 Correct 20 ms 21928 KB Output is correct
11 Correct 20 ms 21948 KB Output is correct
12 Correct 21 ms 21948 KB Output is correct
13 Correct 20 ms 21948 KB Output is correct
14 Correct 21 ms 21964 KB Output is correct
15 Correct 21 ms 21964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 21964 KB Output is correct
2 Correct 19 ms 21968 KB Output is correct
3 Correct 21 ms 21968 KB Output is correct
4 Correct 20 ms 22008 KB Output is correct
5 Correct 20 ms 22008 KB Output is correct
6 Correct 20 ms 22008 KB Output is correct
7 Correct 21 ms 22008 KB Output is correct
8 Correct 20 ms 22008 KB Output is correct
9 Correct 25 ms 22008 KB Output is correct
10 Correct 20 ms 22008 KB Output is correct
11 Correct 21 ms 22012 KB Output is correct
12 Correct 22 ms 22012 KB Output is correct
13 Correct 20 ms 22012 KB Output is correct
14 Correct 20 ms 22012 KB Output is correct
15 Correct 21 ms 22012 KB Output is correct
16 Correct 21 ms 22012 KB Output is correct
17 Correct 20 ms 22268 KB Output is correct
18 Correct 22 ms 22268 KB Output is correct
19 Correct 20 ms 22268 KB Output is correct
20 Correct 19 ms 22268 KB Output is correct
21 Correct 21 ms 22268 KB Output is correct
22 Correct 20 ms 22268 KB Output is correct
23 Correct 21 ms 22268 KB Output is correct
24 Correct 23 ms 22368 KB Output is correct
25 Correct 20 ms 22368 KB Output is correct
26 Correct 19 ms 22368 KB Output is correct
27 Correct 20 ms 22368 KB Output is correct
28 Correct 22 ms 22652 KB Output is correct
29 Correct 24 ms 23420 KB Output is correct
30 Correct 21 ms 23420 KB Output is correct
31 Correct 21 ms 23420 KB Output is correct
32 Correct 22 ms 23420 KB Output is correct
33 Correct 27 ms 24600 KB Output is correct
34 Correct 28 ms 24832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24832 KB Output is correct
2 Correct 18 ms 24832 KB Output is correct
3 Correct 19 ms 24832 KB Output is correct
4 Correct 20 ms 24832 KB Output is correct
5 Correct 18 ms 24832 KB Output is correct
6 Correct 21 ms 24832 KB Output is correct
7 Correct 19 ms 24832 KB Output is correct
8 Correct 19 ms 24832 KB Output is correct
9 Correct 19 ms 24832 KB Output is correct
10 Correct 20 ms 24832 KB Output is correct
11 Correct 20 ms 24832 KB Output is correct
12 Correct 20 ms 24832 KB Output is correct
13 Correct 20 ms 24832 KB Output is correct
14 Correct 19 ms 24832 KB Output is correct
15 Correct 21 ms 24832 KB Output is correct
16 Correct 19 ms 24832 KB Output is correct
17 Correct 21 ms 24832 KB Output is correct
18 Correct 19 ms 24832 KB Output is correct
19 Correct 21 ms 24832 KB Output is correct
20 Correct 21 ms 24832 KB Output is correct
21 Correct 19 ms 24832 KB Output is correct
22 Correct 20 ms 24832 KB Output is correct
23 Correct 22 ms 24832 KB Output is correct
24 Correct 21 ms 24832 KB Output is correct
25 Correct 22 ms 24832 KB Output is correct
26 Correct 20 ms 24832 KB Output is correct
27 Correct 20 ms 24832 KB Output is correct
28 Correct 22 ms 24832 KB Output is correct
29 Correct 23 ms 24832 KB Output is correct
30 Correct 21 ms 24832 KB Output is correct
31 Correct 21 ms 24832 KB Output is correct
32 Correct 21 ms 24832 KB Output is correct
33 Correct 26 ms 24832 KB Output is correct
34 Correct 28 ms 24832 KB Output is correct
35 Correct 44 ms 25172 KB Output is correct
36 Correct 25 ms 25172 KB Output is correct
37 Correct 46 ms 26900 KB Output is correct
38 Correct 54 ms 26900 KB Output is correct
39 Correct 51 ms 26900 KB Output is correct
40 Correct 53 ms 26900 KB Output is correct
41 Correct 55 ms 27008 KB Output is correct
42 Correct 25 ms 27008 KB Output is correct
43 Correct 25 ms 27008 KB Output is correct
44 Correct 27 ms 27008 KB Output is correct
45 Correct 57 ms 31884 KB Output is correct
46 Correct 55 ms 31884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31884 KB Output is correct
2 Correct 19 ms 31884 KB Output is correct
3 Correct 22 ms 31884 KB Output is correct
4 Correct 19 ms 31884 KB Output is correct
5 Correct 19 ms 31884 KB Output is correct
6 Correct 20 ms 31884 KB Output is correct
7 Correct 19 ms 31884 KB Output is correct
8 Correct 18 ms 31884 KB Output is correct
9 Correct 19 ms 31884 KB Output is correct
10 Correct 20 ms 31884 KB Output is correct
11 Correct 23 ms 31884 KB Output is correct
12 Correct 19 ms 31884 KB Output is correct
13 Correct 19 ms 31884 KB Output is correct
14 Correct 23 ms 31884 KB Output is correct
15 Correct 19 ms 31884 KB Output is correct
16 Correct 21 ms 31884 KB Output is correct
17 Correct 21 ms 31884 KB Output is correct
18 Correct 21 ms 31884 KB Output is correct
19 Correct 19 ms 31884 KB Output is correct
20 Correct 19 ms 31884 KB Output is correct
21 Correct 18 ms 31884 KB Output is correct
22 Correct 20 ms 31884 KB Output is correct
23 Correct 19 ms 31884 KB Output is correct
24 Correct 21 ms 31884 KB Output is correct
25 Correct 24 ms 31884 KB Output is correct
26 Correct 20 ms 31884 KB Output is correct
27 Correct 20 ms 31884 KB Output is correct
28 Correct 20 ms 31884 KB Output is correct
29 Correct 24 ms 31884 KB Output is correct
30 Correct 21 ms 31884 KB Output is correct
31 Correct 21 ms 31884 KB Output is correct
32 Correct 20 ms 31884 KB Output is correct
33 Correct 26 ms 31884 KB Output is correct
34 Correct 32 ms 31884 KB Output is correct
35 Correct 44 ms 31884 KB Output is correct
36 Correct 23 ms 31884 KB Output is correct
37 Correct 48 ms 31884 KB Output is correct
38 Correct 53 ms 31884 KB Output is correct
39 Correct 53 ms 31884 KB Output is correct
40 Correct 53 ms 31884 KB Output is correct
41 Correct 70 ms 31884 KB Output is correct
42 Correct 26 ms 31884 KB Output is correct
43 Correct 23 ms 31884 KB Output is correct
44 Correct 24 ms 31884 KB Output is correct
45 Correct 53 ms 31900 KB Output is correct
46 Correct 53 ms 31900 KB Output is correct
47 Correct 88 ms 40776 KB Output is correct
48 Correct 45 ms 40776 KB Output is correct
49 Correct 37 ms 40776 KB Output is correct
50 Correct 33 ms 40776 KB Output is correct
51 Correct 72 ms 40776 KB Output is correct
52 Correct 84 ms 40776 KB Output is correct
53 Correct 50 ms 40776 KB Output is correct
54 Correct 23 ms 40776 KB Output is correct
55 Correct 24 ms 40776 KB Output is correct
56 Correct 35 ms 40776 KB Output is correct
57 Correct 69 ms 40776 KB Output is correct
58 Correct 29 ms 40776 KB Output is correct
59 Correct 31 ms 40776 KB Output is correct
60 Correct 35 ms 40776 KB Output is correct
61 Correct 32 ms 40776 KB Output is correct
62 Correct 66 ms 40776 KB Output is correct
63 Correct 136 ms 68988 KB Output is correct
64 Correct 150 ms 75988 KB Output is correct
65 Correct 202 ms 95884 KB Output is correct
66 Correct 328 ms 152836 KB Output is correct
67 Correct 342 ms 153100 KB Output is correct