Submission #736598

# Submission time Handle Problem Language Result Execution time Memory
736598 2023-05-06T02:02:15 Z minhcool Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
955 ms 11540 KB
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e4 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, m;
int b[N], p[N];
 
bool vis[N][205];
 
int mn_dist[N];
 
vector<int> doges[N];
 
priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> pq;
 
bool beg[N];
 
void process(){
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		cin >> b[i] >> p[i];
		b[i]++;
		doges[b[i]].pb(p[i]);
	}
	for(int i = 1; i <= n; i++) mn_dist[i] = oo;
	pq.push({0, {b[1], p[1]}});
	mn_dist[b[1]] = 0;
	if(p[1] <= 200) vis[b[1]][p[1]] = 1;
	while(!pq.empty()){
		int d = pq.top().fi, u = pq.top().se.fi, p = pq.top().se.se;
		pq.pop();
		if(p <= 200){
			if((u > p) && !vis[u - p][p]){
				vis[u - p][p] = 1;
				mn_dist[u - p] = min(mn_dist[u - p], d + 1);
				pq.push({d + 1, {u - p, p}});
			}	
			if((u + p) <= n && !vis[u + p][p]){
				vis[u + p][p] = 1;
				mn_dist[u + p] = min(mn_dist[u + p], d + 1);
				pq.push({d + 1, {u + p, p}});
			}
		}
		if(d == mn_dist[u] && !beg[u]){
			beg[u] = 1;
			for(auto it : doges[u]){
				if(it <= 200){
					vis[u][it] = 1;
					pq.push({d, {u, it}});
				}
				else{
					for(int i = (u % it); i <= n; i += it){
						if(!i) continue;
						int dist = abs(i - u) / it;
						if(mn_dist[i] > (mn_dist[u] + dist)){
							mn_dist[i] = mn_dist[u] + dist;
							pq.push({mn_dist[i], {i, it}});
						}
					}
				}
			}
		}
	}
	cout << (mn_dist[b[2]] == oo ? -1 : mn_dist[b[2]]) << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	//freopen("doge.inp", "r", stdin);
	//freopen("doge.out", "w", stdout);
	cin.tie(0);
	process();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 984 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 4 ms 1492 KB Output is correct
25 Correct 2 ms 1492 KB Output is correct
26 Correct 2 ms 1560 KB Output is correct
27 Correct 2 ms 1620 KB Output is correct
28 Correct 3 ms 1492 KB Output is correct
29 Correct 7 ms 1492 KB Output is correct
30 Correct 3 ms 1364 KB Output is correct
31 Correct 6 ms 1532 KB Output is correct
32 Correct 4 ms 1492 KB Output is correct
33 Correct 15 ms 1620 KB Output is correct
34 Correct 14 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 3 ms 1568 KB Output is correct
25 Correct 2 ms 1564 KB Output is correct
26 Correct 2 ms 1620 KB Output is correct
27 Correct 2 ms 1620 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 8 ms 1540 KB Output is correct
30 Correct 3 ms 1364 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 3 ms 1492 KB Output is correct
33 Correct 16 ms 1636 KB Output is correct
34 Correct 15 ms 1620 KB Output is correct
35 Correct 15 ms 2556 KB Output is correct
36 Correct 3 ms 1492 KB Output is correct
37 Correct 21 ms 2464 KB Output is correct
38 Correct 20 ms 2900 KB Output is correct
39 Correct 19 ms 2868 KB Output is correct
40 Correct 20 ms 2900 KB Output is correct
41 Correct 18 ms 2888 KB Output is correct
42 Correct 9 ms 3280 KB Output is correct
43 Correct 13 ms 3284 KB Output is correct
44 Correct 9 ms 3324 KB Output is correct
45 Correct 77 ms 3164 KB Output is correct
46 Correct 67 ms 3184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 1236 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 4 ms 1492 KB Output is correct
25 Correct 2 ms 1492 KB Output is correct
26 Correct 2 ms 1620 KB Output is correct
27 Correct 2 ms 1620 KB Output is correct
28 Correct 3 ms 1560 KB Output is correct
29 Correct 7 ms 1432 KB Output is correct
30 Correct 3 ms 1428 KB Output is correct
31 Correct 5 ms 1492 KB Output is correct
32 Correct 3 ms 1492 KB Output is correct
33 Correct 14 ms 1620 KB Output is correct
34 Correct 14 ms 1560 KB Output is correct
35 Correct 13 ms 2588 KB Output is correct
36 Correct 3 ms 1492 KB Output is correct
37 Correct 20 ms 2456 KB Output is correct
38 Correct 20 ms 2896 KB Output is correct
39 Correct 19 ms 2864 KB Output is correct
40 Correct 18 ms 3008 KB Output is correct
41 Correct 19 ms 2900 KB Output is correct
42 Correct 11 ms 3284 KB Output is correct
43 Correct 10 ms 3284 KB Output is correct
44 Correct 8 ms 3324 KB Output is correct
45 Correct 61 ms 3172 KB Output is correct
46 Correct 62 ms 3208 KB Output is correct
47 Correct 77 ms 5328 KB Output is correct
48 Correct 6 ms 2260 KB Output is correct
49 Correct 7 ms 2204 KB Output is correct
50 Correct 5 ms 1964 KB Output is correct
51 Correct 44 ms 9280 KB Output is correct
52 Correct 45 ms 9272 KB Output is correct
53 Correct 15 ms 8712 KB Output is correct
54 Correct 5 ms 7312 KB Output is correct
55 Correct 5 ms 7252 KB Output is correct
56 Correct 14 ms 8816 KB Output is correct
57 Correct 50 ms 7480 KB Output is correct
58 Correct 14 ms 9020 KB Output is correct
59 Correct 15 ms 9116 KB Output is correct
60 Correct 19 ms 9044 KB Output is correct
61 Correct 16 ms 9124 KB Output is correct
62 Correct 29 ms 8992 KB Output is correct
63 Correct 43 ms 10896 KB Output is correct
64 Correct 48 ms 11008 KB Output is correct
65 Correct 276 ms 11284 KB Output is correct
66 Correct 953 ms 11380 KB Output is correct
67 Correct 955 ms 11540 KB Output is correct