답안 #133543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133543 2019-07-21T04:23:07 Z junodeveloper Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
291 ms 68196 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
int n,m;
int B[30010],P[30010],D[30010];
set<int> ps[30010];
vector<pi> adj[30010];
int main() {
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<m;i++) {
		scanf("%d%d", B+i, P+i);
		ps[B[i]].insert(P[i]);
	}
	for(i=0;i<n;i++) {
		int cur;
		for(auto& it:ps[i]) {
			cur=i-it;
			while(cur>=0) {
				adj[i].push_back({cur,(i-cur)/it});
				if(ps[cur].find(it)!=ps[cur].end()) break;
				cur-=it;
			}
			cur=i+it;
			while(cur<n) {
				adj[i].push_back({cur,(cur-i)/it});
				if(ps[cur].find(it)!=ps[cur].end()) break;
				cur+=it;
			}
		}
	}
	fill(D,D+n,(int)1e9);
	priority_queue<pi,vector<pi>,greater<pi> > pq;
	pq.push({0,B[0]}); D[B[0]]=0;
	while(!pq.empty()) {
		int w,u; tie(w,u)=pq.top(); pq.pop();
		if(D[u]<w) continue;
		if(u==B[1]) break;
		for(auto& it:adj[u]) {
			if(w+it.se<D[it.fi]) {
				D[it.fi]=w+it.se;
				pq.push({D[it.fi],it.fi});
			}
		}
	}
	printf("%d\n", D[B[1]]==(int)1e9?-1:D[B[1]]);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:16:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
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: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);
   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2396 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2428 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 4 ms 2552 KB Output is correct
13 Correct 4 ms 2552 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2512 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2552 KB Output is correct
11 Correct 5 ms 2552 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2552 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2656 KB Output is correct
16 Correct 4 ms 2552 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 5 ms 2552 KB Output is correct
19 Correct 4 ms 2552 KB Output is correct
20 Correct 5 ms 2680 KB Output is correct
21 Correct 5 ms 2552 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 6 ms 2552 KB Output is correct
24 Correct 6 ms 2808 KB Output is correct
25 Correct 5 ms 2680 KB Output is correct
26 Correct 4 ms 2552 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 8 ms 3320 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
31 Correct 6 ms 2936 KB Output is correct
32 Correct 5 ms 2812 KB Output is correct
33 Correct 10 ms 4088 KB Output is correct
34 Correct 9 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2428 KB Output is correct
2 Correct 4 ms 2468 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2556 KB Output is correct
11 Correct 5 ms 2552 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2552 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 6 ms 2680 KB Output is correct
16 Correct 5 ms 2480 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 5 ms 2556 KB Output is correct
19 Correct 5 ms 2516 KB Output is correct
20 Correct 5 ms 2680 KB Output is correct
21 Correct 5 ms 2596 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 6 ms 2552 KB Output is correct
24 Correct 7 ms 2808 KB Output is correct
25 Correct 5 ms 2684 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 8 ms 3320 KB Output is correct
30 Correct 9 ms 2784 KB Output is correct
31 Correct 6 ms 2908 KB Output is correct
32 Correct 5 ms 2812 KB Output is correct
33 Correct 12 ms 4088 KB Output is correct
34 Correct 10 ms 4088 KB Output is correct
35 Correct 33 ms 5116 KB Output is correct
36 Correct 7 ms 2936 KB Output is correct
37 Correct 84 ms 5724 KB Output is correct
38 Correct 36 ms 6264 KB Output is correct
39 Correct 37 ms 6108 KB Output is correct
40 Correct 33 ms 6008 KB Output is correct
41 Correct 33 ms 6136 KB Output is correct
42 Correct 11 ms 3064 KB Output is correct
43 Correct 10 ms 2936 KB Output is correct
44 Correct 11 ms 3064 KB Output is correct
45 Correct 35 ms 8824 KB Output is correct
46 Correct 33 ms 8824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2472 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2428 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2428 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 5 ms 2652 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2424 KB Output is correct
14 Correct 5 ms 2552 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2552 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2616 KB Output is correct
19 Correct 4 ms 2552 KB Output is correct
20 Correct 5 ms 2680 KB Output is correct
21 Correct 4 ms 2552 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 5 ms 2596 KB Output is correct
24 Correct 6 ms 2808 KB Output is correct
25 Correct 5 ms 2680 KB Output is correct
26 Correct 5 ms 2680 KB Output is correct
27 Correct 4 ms 2552 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 8 ms 3320 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
31 Correct 6 ms 2936 KB Output is correct
32 Correct 5 ms 2808 KB Output is correct
33 Correct 11 ms 4088 KB Output is correct
34 Correct 9 ms 4088 KB Output is correct
35 Correct 25 ms 5112 KB Output is correct
36 Correct 7 ms 2936 KB Output is correct
37 Correct 28 ms 5756 KB Output is correct
38 Correct 33 ms 6136 KB Output is correct
39 Correct 34 ms 6264 KB Output is correct
40 Correct 33 ms 6112 KB Output is correct
41 Correct 33 ms 6264 KB Output is correct
42 Correct 10 ms 2952 KB Output is correct
43 Correct 10 ms 2936 KB Output is correct
44 Correct 10 ms 3064 KB Output is correct
45 Correct 36 ms 8824 KB Output is correct
46 Correct 34 ms 8824 KB Output is correct
47 Correct 64 ms 13272 KB Output is correct
48 Correct 26 ms 6388 KB Output is correct
49 Correct 21 ms 5496 KB Output is correct
50 Correct 20 ms 4984 KB Output is correct
51 Correct 45 ms 8576 KB Output is correct
52 Correct 44 ms 8892 KB Output is correct
53 Correct 22 ms 5592 KB Output is correct
54 Correct 6 ms 3064 KB Output is correct
55 Correct 8 ms 3572 KB Output is correct
56 Correct 20 ms 5368 KB Output is correct
57 Correct 25 ms 11388 KB Output is correct
58 Correct 14 ms 3872 KB Output is correct
59 Correct 15 ms 4360 KB Output is correct
60 Correct 16 ms 5080 KB Output is correct
61 Correct 16 ms 4472 KB Output is correct
62 Correct 33 ms 9592 KB Output is correct
63 Correct 102 ms 26864 KB Output is correct
64 Correct 116 ms 29900 KB Output is correct
65 Correct 152 ms 39696 KB Output is correct
66 Correct 291 ms 68196 KB Output is correct
67 Correct 226 ms 68040 KB Output is correct