답안 #537208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537208 2022-03-14T18:15:32 Z Gurban Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
384 ms 262144 KB
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const int maxn=3e4+5;
const int B = 180;
int n,m;
int b[maxn],p[maxn];
int ver[maxn][B];
int dis[maxn * B];
bool vis[maxn * B];
vector<pair<int,int>>E[maxn * B];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	int sq = sqrt(n) + 2;
	int sz = n - 1;
	for(int i = 0;i < n;i++) for(int j = 1;j <= sq;j++) ver[i][j] = ++sz;
	for(int i = 0;i < n;i++){
		for(int j = 1;j <= sq;j++){
			E[ver[i][j]].push_back({i,0});
			// E[i].push_back({ver[i][j],0});
			if(i - j >= 0) E[ver[i][j]].push_back({ver[i-j][j],1});
			if(i + j < n) E[ver[i][j]].push_back({ver[i+j][j],1});
		}
	}
	for(int i = 0;i < m;i++){
		cin >> b[i] >> p[i];
		if(p[i] <= sq){
			E[b[i]].push_back({ver[b[i]][p[i]],0});
			E[ver[b[i]][p[i]]].push_back({b[i],0});
		}
		else {
			for(int j = 1;b[i] - j * p[i] >= 0;j++) E[b[i]].push_back({b[i] - j * p[i],j});
			for(int j = 1;b[i] + j * p[i] < n;j++) E[b[i]].push_back({b[i] + j * p[i],j});
		}
	}

	// cout<<E[22][0].first<<' '<<E[22][0].second<<'\n';

	for(int i = 0;i <= sz;i++) dis[i] = 1e9;
	dis[b[0]] = 0;
	priority_queue<pair<int,int>>q;
	q.push({0,b[0]});
	while(!q.empty()){
		int x = q.top().second;
		q.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		// cout<<x<<'\n';
		for(auto i : E[x]){
			if(dis[i.first] > dis[x] + i.second){
				dis[i.first] = dis[x] + i.second;
				q.push({-dis[i.first],i.first});
			}
		}
	}
	if(dis[b[1]] == 1e9) cout<<-1;
	else cout<<dis[b[1]];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 127196 KB Output is correct
2 Correct 61 ms 127052 KB Output is correct
3 Correct 62 ms 127076 KB Output is correct
4 Correct 69 ms 127052 KB Output is correct
5 Correct 67 ms 127052 KB Output is correct
6 Correct 63 ms 127116 KB Output is correct
7 Correct 66 ms 127160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 127052 KB Output is correct
2 Correct 63 ms 127088 KB Output is correct
3 Correct 63 ms 127048 KB Output is correct
4 Correct 61 ms 127124 KB Output is correct
5 Correct 64 ms 127112 KB Output is correct
6 Correct 61 ms 127172 KB Output is correct
7 Correct 66 ms 127148 KB Output is correct
8 Correct 62 ms 127128 KB Output is correct
9 Correct 64 ms 127176 KB Output is correct
10 Correct 65 ms 127288 KB Output is correct
11 Correct 72 ms 127348 KB Output is correct
12 Correct 63 ms 127332 KB Output is correct
13 Correct 63 ms 127272 KB Output is correct
14 Correct 68 ms 127336 KB Output is correct
15 Correct 63 ms 127308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 127052 KB Output is correct
2 Correct 64 ms 127056 KB Output is correct
3 Correct 63 ms 127100 KB Output is correct
4 Correct 63 ms 127080 KB Output is correct
5 Correct 62 ms 127152 KB Output is correct
6 Correct 62 ms 127120 KB Output is correct
7 Correct 66 ms 127104 KB Output is correct
8 Correct 64 ms 127212 KB Output is correct
9 Correct 63 ms 127192 KB Output is correct
10 Correct 64 ms 127400 KB Output is correct
11 Correct 62 ms 127404 KB Output is correct
12 Correct 64 ms 127504 KB Output is correct
13 Correct 63 ms 127276 KB Output is correct
14 Correct 63 ms 127288 KB Output is correct
15 Correct 62 ms 127252 KB Output is correct
16 Correct 63 ms 127432 KB Output is correct
17 Correct 71 ms 128872 KB Output is correct
18 Correct 73 ms 132296 KB Output is correct
19 Correct 75 ms 133160 KB Output is correct
20 Correct 76 ms 133332 KB Output is correct
21 Correct 73 ms 127872 KB Output is correct
22 Correct 81 ms 132376 KB Output is correct
23 Correct 71 ms 131640 KB Output is correct
24 Correct 76 ms 133060 KB Output is correct
25 Correct 74 ms 133324 KB Output is correct
26 Correct 86 ms 133376 KB Output is correct
27 Correct 75 ms 133312 KB Output is correct
28 Correct 79 ms 133432 KB Output is correct
29 Correct 84 ms 133372 KB Output is correct
30 Correct 77 ms 133216 KB Output is correct
31 Correct 78 ms 133284 KB Output is correct
32 Correct 85 ms 133452 KB Output is correct
33 Correct 91 ms 133984 KB Output is correct
34 Correct 86 ms 133836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 127148 KB Output is correct
2 Correct 62 ms 127168 KB Output is correct
3 Correct 63 ms 127164 KB Output is correct
4 Correct 62 ms 127140 KB Output is correct
5 Correct 70 ms 127084 KB Output is correct
6 Correct 64 ms 127176 KB Output is correct
7 Correct 65 ms 127228 KB Output is correct
8 Correct 63 ms 127144 KB Output is correct
9 Correct 63 ms 127232 KB Output is correct
10 Correct 64 ms 127260 KB Output is correct
11 Correct 64 ms 127308 KB Output is correct
12 Correct 63 ms 127376 KB Output is correct
13 Correct 63 ms 127308 KB Output is correct
14 Correct 63 ms 127368 KB Output is correct
15 Correct 63 ms 127356 KB Output is correct
16 Correct 65 ms 127472 KB Output is correct
17 Correct 69 ms 128896 KB Output is correct
18 Correct 71 ms 132252 KB Output is correct
19 Correct 75 ms 133232 KB Output is correct
20 Correct 72 ms 133420 KB Output is correct
21 Correct 63 ms 127892 KB Output is correct
22 Correct 74 ms 132352 KB Output is correct
23 Correct 71 ms 131700 KB Output is correct
24 Correct 83 ms 133212 KB Output is correct
25 Correct 76 ms 133388 KB Output is correct
26 Correct 77 ms 133332 KB Output is correct
27 Correct 78 ms 133412 KB Output is correct
28 Correct 75 ms 133400 KB Output is correct
29 Correct 82 ms 133320 KB Output is correct
30 Correct 77 ms 133288 KB Output is correct
31 Correct 82 ms 133384 KB Output is correct
32 Correct 79 ms 133448 KB Output is correct
33 Correct 90 ms 133912 KB Output is correct
34 Correct 86 ms 133928 KB Output is correct
35 Correct 81 ms 132172 KB Output is correct
36 Correct 67 ms 129964 KB Output is correct
37 Correct 90 ms 134976 KB Output is correct
38 Correct 92 ms 134964 KB Output is correct
39 Correct 91 ms 134880 KB Output is correct
40 Correct 93 ms 134884 KB Output is correct
41 Correct 93 ms 135000 KB Output is correct
42 Correct 80 ms 134448 KB Output is correct
43 Correct 80 ms 134412 KB Output is correct
44 Correct 80 ms 134392 KB Output is correct
45 Correct 96 ms 137648 KB Output is correct
46 Correct 98 ms 137820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 127248 KB Output is correct
2 Correct 62 ms 127052 KB Output is correct
3 Correct 61 ms 127076 KB Output is correct
4 Correct 62 ms 127096 KB Output is correct
5 Correct 62 ms 127108 KB Output is correct
6 Correct 68 ms 127132 KB Output is correct
7 Correct 62 ms 127140 KB Output is correct
8 Correct 64 ms 127180 KB Output is correct
9 Correct 63 ms 127180 KB Output is correct
10 Correct 62 ms 127312 KB Output is correct
11 Correct 63 ms 127308 KB Output is correct
12 Correct 62 ms 127308 KB Output is correct
13 Correct 63 ms 127348 KB Output is correct
14 Correct 66 ms 127288 KB Output is correct
15 Correct 62 ms 127376 KB Output is correct
16 Correct 64 ms 127404 KB Output is correct
17 Correct 65 ms 128860 KB Output is correct
18 Correct 75 ms 132240 KB Output is correct
19 Correct 76 ms 133208 KB Output is correct
20 Correct 79 ms 133412 KB Output is correct
21 Correct 71 ms 127820 KB Output is correct
22 Correct 73 ms 132364 KB Output is correct
23 Correct 72 ms 131620 KB Output is correct
24 Correct 76 ms 132976 KB Output is correct
25 Correct 75 ms 133332 KB Output is correct
26 Correct 80 ms 133404 KB Output is correct
27 Correct 77 ms 133424 KB Output is correct
28 Correct 87 ms 133360 KB Output is correct
29 Correct 96 ms 133296 KB Output is correct
30 Correct 79 ms 133268 KB Output is correct
31 Correct 77 ms 133384 KB Output is correct
32 Correct 84 ms 133404 KB Output is correct
33 Correct 87 ms 133916 KB Output is correct
34 Correct 86 ms 133852 KB Output is correct
35 Correct 83 ms 132044 KB Output is correct
36 Correct 82 ms 130036 KB Output is correct
37 Correct 89 ms 134776 KB Output is correct
38 Correct 94 ms 134892 KB Output is correct
39 Correct 90 ms 134976 KB Output is correct
40 Correct 90 ms 134956 KB Output is correct
41 Correct 97 ms 134988 KB Output is correct
42 Correct 84 ms 134440 KB Output is correct
43 Correct 78 ms 134316 KB Output is correct
44 Correct 79 ms 134404 KB Output is correct
45 Correct 94 ms 137632 KB Output is correct
46 Correct 99 ms 137856 KB Output is correct
47 Correct 384 ms 212960 KB Output is correct
48 Runtime error 325 ms 262144 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -