답안 #236177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236177 2020-05-31T12:48:20 Z thtsshz_bgwrswh Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
358 ms 8692 KB
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#include<algorithm>
using namespace std;
int pos[30005],power[30005],dis[30005];
vector<pair<int,int>> g[30005];
set<int> s[30005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
int main(){
	int i,n,m;
	scanf("%d%d",&n,&m);	
	for(i=0;i<m;i++){
		scanf("%d%d",&pos[i],&power[i]);
		s[pos[i]].insert(power[i]);
	}
	for(i=0;i<n;i++)
		dis[i]=1000000000;
	dis[pos[0]]=0;
	pq.push({0,pos[0]});
	while(pq.size()){
		auto v=pq.top().second;
		pq.pop();
		if(v==pos[1]){
			printf("%d\n",dis[pos[1]]);
			return 0;
		}
		for(auto x:s[v]){
			for(i=v+x;i<n;i+=x){
				if(dis[i]>dis[v]+(i-v)/x){
					dis[i]=dis[v]+(i-v)/x;
					pq.push({dis[i],i});
				}
				if(s[i].count(x))
					break;
			}
			for(i=v-x;i>=0;i-=x){
				if(dis[i]>dis[v]+(v-i)/x){
					dis[i]=dis[v]+(v-i)/x;
					pq.push({dis[i],i});
				}
				if(s[i].count(x))
					break;
			}
		}
	}
	puts("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15: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:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&pos[i],&power[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 5 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 4 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 8 ms 2464 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2464 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 7 ms 2560 KB Output is correct
18 Correct 7 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 6 ms 2432 KB Output is correct
23 Correct 6 ms 2432 KB Output is correct
24 Correct 7 ms 2560 KB Output is correct
25 Correct 6 ms 2560 KB Output is correct
26 Correct 6 ms 2432 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 7 ms 2560 KB Output is correct
29 Correct 8 ms 2688 KB Output is correct
30 Correct 7 ms 2560 KB Output is correct
31 Correct 7 ms 2560 KB Output is correct
32 Correct 7 ms 2560 KB Output is correct
33 Correct 12 ms 2944 KB Output is correct
34 Correct 10 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2464 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 6 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 7 ms 2560 KB Output is correct
18 Correct 7 ms 2432 KB Output is correct
19 Correct 6 ms 2432 KB Output is correct
20 Correct 6 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2432 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 7 ms 2560 KB Output is correct
25 Correct 6 ms 2560 KB Output is correct
26 Correct 6 ms 2432 KB Output is correct
27 Correct 7 ms 2560 KB Output is correct
28 Correct 6 ms 2560 KB Output is correct
29 Correct 8 ms 2688 KB Output is correct
30 Correct 6 ms 2560 KB Output is correct
31 Correct 7 ms 2560 KB Output is correct
32 Correct 6 ms 2560 KB Output is correct
33 Correct 12 ms 2944 KB Output is correct
34 Correct 10 ms 2976 KB Output is correct
35 Correct 20 ms 3840 KB Output is correct
36 Correct 8 ms 2688 KB Output is correct
37 Correct 19 ms 3584 KB Output is correct
38 Correct 22 ms 4224 KB Output is correct
39 Correct 18 ms 4096 KB Output is correct
40 Correct 19 ms 4224 KB Output is correct
41 Correct 21 ms 4224 KB Output is correct
42 Correct 11 ms 2944 KB Output is correct
43 Correct 11 ms 2944 KB Output is correct
44 Correct 11 ms 2996 KB Output is correct
45 Correct 40 ms 4736 KB Output is correct
46 Correct 33 ms 4712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2560 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 6 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 7 ms 2560 KB Output is correct
18 Correct 6 ms 2612 KB Output is correct
19 Correct 6 ms 2432 KB Output is correct
20 Correct 6 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2432 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 7 ms 2560 KB Output is correct
25 Correct 6 ms 2560 KB Output is correct
26 Correct 6 ms 2432 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 7 ms 2560 KB Output is correct
29 Correct 9 ms 2688 KB Output is correct
30 Correct 7 ms 2560 KB Output is correct
31 Correct 7 ms 2560 KB Output is correct
32 Correct 7 ms 2560 KB Output is correct
33 Correct 12 ms 2944 KB Output is correct
34 Correct 10 ms 2944 KB Output is correct
35 Correct 21 ms 3840 KB Output is correct
36 Correct 8 ms 2688 KB Output is correct
37 Correct 20 ms 3712 KB Output is correct
38 Correct 21 ms 4224 KB Output is correct
39 Correct 19 ms 4096 KB Output is correct
40 Correct 20 ms 4096 KB Output is correct
41 Correct 19 ms 4224 KB Output is correct
42 Correct 11 ms 2944 KB Output is correct
43 Correct 11 ms 2944 KB Output is correct
44 Correct 11 ms 2944 KB Output is correct
45 Correct 43 ms 4736 KB Output is correct
46 Correct 30 ms 4736 KB Output is correct
47 Correct 24 ms 4736 KB Output is correct
48 Correct 16 ms 3968 KB Output is correct
49 Correct 15 ms 3968 KB Output is correct
50 Correct 12 ms 3456 KB Output is correct
51 Correct 33 ms 5120 KB Output is correct
52 Correct 34 ms 5224 KB Output is correct
53 Correct 20 ms 4736 KB Output is correct
54 Correct 7 ms 2816 KB Output is correct
55 Correct 8 ms 2816 KB Output is correct
56 Correct 15 ms 4352 KB Output is correct
57 Correct 7 ms 3072 KB Output is correct
58 Correct 14 ms 3200 KB Output is correct
59 Correct 14 ms 3200 KB Output is correct
60 Correct 14 ms 3200 KB Output is correct
61 Correct 14 ms 3456 KB Output is correct
62 Correct 23 ms 4480 KB Output is correct
63 Correct 70 ms 6648 KB Output is correct
64 Correct 71 ms 6648 KB Output is correct
65 Correct 100 ms 6648 KB Output is correct
66 Correct 358 ms 8684 KB Output is correct
67 Correct 302 ms 8692 KB Output is correct