답안 #206183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206183 2020-03-02T16:00:46 Z mraron Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
672 ms 14956 KB
#include<bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
int n,m;
const int MAXN=30001;
const int lim=80;
int b[MAXN];
int p[MAXN];
int dst[MAXN][lim+1];
int kesz[MAXN];

vector<int> lst_small[MAXN];
vector<int> lst_big[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;++i) {
		cin>>b[i]>>p[i];
		if(p[i]<=lim) lst_small[b[i]].push_back(p[i]);
		else lst_big[b[i]].push_back(p[i]);
	}
	
	for(int i=0;i<n;++i) {
		lst_small[b[i]].push_back(0);
		sort(lst_small[b[i]].begin(), lst_small[b[i]].end());
		lst_small[b[i]].resize(distance(lst_small[b[i]].begin(), unique(lst_small[b[i]].begin(), lst_small[b[i]].end())));
		
		sort(lst_big[b[i]].begin(), lst_big[b[i]].end());
		lst_big[b[i]].resize(distance(lst_big[b[i]].begin(), unique(lst_big[b[i]].begin(), lst_big[b[i]].end())));
	}
	for(int i=0;i<n;++i) {
		for(int j=0;j<=lim;++j) {
			dst[i][j]=1e9;
		}
	}
	
	dst[b[0]][0]=0;
	priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> pq;
	pq.push({0, {b[0], 0}});
	while(!pq.empty()) {
		auto tp=pq.top();
		pq.pop();
		if(tp.xx>dst[tp.yy.xx][tp.yy.yy]) continue ;
		
		if(!kesz[tp.yy.xx]) {
			for(auto i:lst_small[tp.yy.xx]) {
				if(i<=lim) {
					if(tp.xx<dst[tp.yy.xx][i]) {
						dst[tp.yy.xx][i]=tp.xx;
						pq.push({dst[tp.yy.xx][i], {tp.yy.xx, i}});
					}
				}
			}

			for(auto i:lst_big[tp.yy.xx]) {
				for(int j=tp.yy.xx%i;j<n;j+=i) {
					int diff=abs(j-tp.yy.xx)/i;
					if(tp.xx+diff<dst[j][0]) {
						dst[j][0]=tp.xx+diff;
						pq.push({dst[j][0], {j,0}});
					}
				}
			}
		}
		kesz[tp.yy.xx]=1;
		
		if(tp.yy.xx-tp.yy.yy>=0 && tp.xx+1<dst[tp.yy.xx-tp.yy.yy][tp.yy.yy]) {
			dst[tp.yy.xx-tp.yy.yy][tp.yy.yy]=tp.xx+1;
			pq.push({dst[tp.yy.xx-tp.yy.yy][tp.yy.yy], {tp.yy.xx-tp.yy.yy, tp.yy.yy}});
		}
		
		if(tp.yy.xx+tp.yy.yy<n && tp.xx+1<dst[tp.yy.xx+tp.yy.yy][tp.yy.yy]) {
			dst[tp.yy.xx+tp.yy.yy][tp.yy.yy]=tp.xx+1;
			pq.push({dst[tp.yy.xx+tp.yy.yy][tp.yy.yy], {tp.yy.xx+tp.yy.yy, tp.yy.yy}});
		}
	}
	
	if(dst[b[1]][0]==1e9) cout<<-1;
	else cout<<dst[b[1]][0];
	cout<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 5 ms 1788 KB Output is correct
4 Correct 5 ms 1784 KB Output is correct
5 Correct 6 ms 1784 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 5 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 6 ms 1784 KB Output is correct
4 Correct 6 ms 1784 KB Output is correct
5 Correct 5 ms 1784 KB Output is correct
6 Correct 6 ms 1784 KB Output is correct
7 Correct 5 ms 1784 KB Output is correct
8 Correct 5 ms 1784 KB Output is correct
9 Correct 5 ms 1784 KB Output is correct
10 Correct 6 ms 1788 KB Output is correct
11 Correct 7 ms 1912 KB Output is correct
12 Correct 6 ms 1912 KB Output is correct
13 Correct 6 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 5 ms 1784 KB Output is correct
4 Correct 6 ms 1784 KB Output is correct
5 Correct 5 ms 1788 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 5 ms 1912 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 6 ms 1704 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 6 ms 1916 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 6 ms 1784 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 6 ms 1784 KB Output is correct
17 Correct 7 ms 2040 KB Output is correct
18 Correct 6 ms 2424 KB Output is correct
19 Correct 6 ms 2424 KB Output is correct
20 Correct 6 ms 2424 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 7 ms 2424 KB Output is correct
23 Correct 7 ms 2296 KB Output is correct
24 Correct 8 ms 2552 KB Output is correct
25 Correct 7 ms 2552 KB Output is correct
26 Correct 7 ms 2424 KB Output is correct
27 Correct 10 ms 2424 KB Output is correct
28 Correct 8 ms 2552 KB Output is correct
29 Correct 14 ms 2424 KB Output is correct
30 Correct 9 ms 2424 KB Output is correct
31 Correct 10 ms 2424 KB Output is correct
32 Correct 8 ms 2424 KB Output is correct
33 Correct 25 ms 2424 KB Output is correct
34 Correct 22 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 5 ms 1784 KB Output is correct
4 Correct 5 ms 1784 KB Output is correct
5 Correct 5 ms 1784 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 6 ms 1784 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 5 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 6 ms 1912 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 6 ms 1912 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 6 ms 1784 KB Output is correct
17 Correct 8 ms 2040 KB Output is correct
18 Correct 6 ms 2424 KB Output is correct
19 Correct 6 ms 2424 KB Output is correct
20 Correct 7 ms 2424 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 6 ms 2296 KB Output is correct
23 Correct 7 ms 2296 KB Output is correct
24 Correct 8 ms 2424 KB Output is correct
25 Correct 7 ms 2424 KB Output is correct
26 Correct 7 ms 2424 KB Output is correct
27 Correct 10 ms 2424 KB Output is correct
28 Correct 8 ms 2552 KB Output is correct
29 Correct 13 ms 2424 KB Output is correct
30 Correct 8 ms 2424 KB Output is correct
31 Correct 10 ms 2424 KB Output is correct
32 Correct 9 ms 2424 KB Output is correct
33 Correct 25 ms 2424 KB Output is correct
34 Correct 23 ms 2424 KB Output is correct
35 Correct 18 ms 2680 KB Output is correct
36 Correct 8 ms 2168 KB Output is correct
37 Correct 25 ms 2936 KB Output is correct
38 Correct 23 ms 2968 KB Output is correct
39 Correct 23 ms 2936 KB Output is correct
40 Correct 23 ms 3068 KB Output is correct
41 Correct 23 ms 2936 KB Output is correct
42 Correct 11 ms 2816 KB Output is correct
43 Correct 15 ms 2936 KB Output is correct
44 Correct 12 ms 2808 KB Output is correct
45 Correct 39 ms 3132 KB Output is correct
46 Correct 40 ms 3128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1788 KB Output is correct
2 Correct 6 ms 1784 KB Output is correct
3 Correct 5 ms 1784 KB Output is correct
4 Correct 5 ms 1784 KB Output is correct
5 Correct 6 ms 1784 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 5 ms 1784 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 5 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 7 ms 1912 KB Output is correct
12 Correct 6 ms 1788 KB Output is correct
13 Correct 6 ms 1784 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 6 ms 1784 KB Output is correct
17 Correct 8 ms 2040 KB Output is correct
18 Correct 6 ms 2424 KB Output is correct
19 Correct 6 ms 2424 KB Output is correct
20 Correct 7 ms 2424 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 6 ms 2424 KB Output is correct
23 Correct 7 ms 2296 KB Output is correct
24 Correct 8 ms 2424 KB Output is correct
25 Correct 7 ms 2424 KB Output is correct
26 Correct 7 ms 2424 KB Output is correct
27 Correct 10 ms 2424 KB Output is correct
28 Correct 8 ms 2552 KB Output is correct
29 Correct 14 ms 2424 KB Output is correct
30 Correct 8 ms 2424 KB Output is correct
31 Correct 10 ms 2424 KB Output is correct
32 Correct 8 ms 2424 KB Output is correct
33 Correct 24 ms 2552 KB Output is correct
34 Correct 22 ms 2424 KB Output is correct
35 Correct 19 ms 2680 KB Output is correct
36 Correct 8 ms 2168 KB Output is correct
37 Correct 23 ms 3064 KB Output is correct
38 Correct 24 ms 3064 KB Output is correct
39 Correct 23 ms 2940 KB Output is correct
40 Correct 23 ms 2936 KB Output is correct
41 Correct 22 ms 2936 KB Output is correct
42 Correct 12 ms 2816 KB Output is correct
43 Correct 15 ms 2808 KB Output is correct
44 Correct 13 ms 2936 KB Output is correct
45 Correct 41 ms 3132 KB Output is correct
46 Correct 40 ms 3128 KB Output is correct
47 Correct 72 ms 7096 KB Output is correct
48 Correct 21 ms 10232 KB Output is correct
49 Correct 20 ms 10872 KB Output is correct
50 Correct 18 ms 11384 KB Output is correct
51 Correct 64 ms 13368 KB Output is correct
52 Correct 65 ms 13368 KB Output is correct
53 Correct 31 ms 12792 KB Output is correct
54 Correct 13 ms 11384 KB Output is correct
55 Correct 13 ms 11384 KB Output is correct
56 Correct 26 ms 12540 KB Output is correct
57 Correct 84 ms 11512 KB Output is correct
58 Correct 25 ms 12024 KB Output is correct
59 Correct 23 ms 11896 KB Output is correct
60 Correct 30 ms 11896 KB Output is correct
61 Correct 672 ms 12024 KB Output is correct
62 Correct 46 ms 13432 KB Output is correct
63 Correct 86 ms 13428 KB Output is correct
64 Correct 102 ms 13420 KB Output is correct
65 Correct 134 ms 14956 KB Output is correct
66 Correct 526 ms 14896 KB Output is correct
67 Correct 538 ms 14956 KB Output is correct