Submission #527458

# Submission time Handle Problem Language Result Execution time Memory
527458 2022-02-17T12:47:56 Z Koosha_mv Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
361 ms 62152 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
#define pii pair<int,pair<int,int>>

const int N=50000,S=42,inf=1e15;
 
int m,n,pos[N],p[N],dist[N][S],mark[N][S];
vector<int> vec[N];
priority_queue<pii,vector<pii>,greater<pii>> st;
 
main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>m;
	f(i,0,m){
		cin>>pos[i]>>p[i];
		vec[pos[i]].pb(p[i]);
	}
	f(i,0,n) f(j,0,S) dist[i][j]=inf;
	dist[pos[0]][0]=0;
	f(i,0,n) f(j,0,S) st.push({dist[i][j],{i,j}});
	while(st.size()){
		int x=st.top().S.F,p=st.top().S.S;
		st.pop();
		if(mark[x][p]) continue ;
		if(dist[x][p]==N) break;
		//cout<<endl;
		//eror(dist[2][0]);
		//cout<<x<<" "<<p<<" -> "<<dist[x][p]<<endl;
		mark[x][p]=1;
		if(p>0){
			//eror(x+p);
			//cout<<x+p<<" "<<dist[x][p]+1<<" "<<dist[x+p][0]<<endl;
			if(x+p<n && dist[x][p]+1<dist[x+p][0]){
				//eror(100);
				dist[x+p][0]=dist[x][p]+1;
				st.push({dist[x+p][0],{x+p,0}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][0]){
				dist[x-p][0]=dist[x][p]+1;
				st.push({dist[x-p][0],{x-p,0}});
			}
			
			if(x+p<n && dist[x][p]+1<dist[x+p][p]){
				dist[x+p][p]=dist[x][p]+1;
				st.push({dist[x+p][p],{x+p,p}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][p]){
				dist[x-p][p]=dist[x][p]+1;
				st.push({dist[x-p][p],{x-p,p}});
			}
			continue ;
		}
		for(auto u : vec[x]){
			if(u<S){
				if(dist[x][u]<dist[x][p]) assert(0);
				if(dist[x][u]==dist[x][p]) continue ;
				dist[x][u]=dist[x][p];
				st.push({dist[x][u],{x,u}});
			}
			else{
				for(int i=x%u;i<n;i+=u){
					if(dist[x][p]+abs(x-i)/u<dist[i][p]){
						dist[i][p]=dist[x][p]+abs(x-i)/u;
						st.push({dist[i][p],{i,p}});
					}
				}
			}
		}
	}
	cout<<(dist[pos[1]][0]==inf ? -1 : dist[pos[1]][0]);
}

Compilation message

skyscraper.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 2 ms 1688 KB Output is correct
10 Correct 3 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 3 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 2 ms 1804 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 3 ms 1868 KB Output is correct
16 Correct 2 ms 2060 KB Output is correct
17 Correct 7 ms 2884 KB Output is correct
18 Correct 14 ms 5316 KB Output is correct
19 Correct 15 ms 5384 KB Output is correct
20 Correct 15 ms 5440 KB Output is correct
21 Correct 5 ms 2504 KB Output is correct
22 Correct 13 ms 5336 KB Output is correct
23 Correct 13 ms 5184 KB Output is correct
24 Correct 15 ms 5440 KB Output is correct
25 Correct 17 ms 5440 KB Output is correct
26 Correct 17 ms 5452 KB Output is correct
27 Correct 17 ms 5452 KB Output is correct
28 Correct 17 ms 5440 KB Output is correct
29 Correct 26 ms 5312 KB Output is correct
30 Correct 17 ms 5324 KB Output is correct
31 Correct 18 ms 5316 KB Output is correct
32 Correct 16 ms 5312 KB Output is correct
33 Correct 26 ms 5452 KB Output is correct
34 Correct 27 ms 5448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1848 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 2060 KB Output is correct
17 Correct 8 ms 2884 KB Output is correct
18 Correct 13 ms 5316 KB Output is correct
19 Correct 14 ms 5324 KB Output is correct
20 Correct 15 ms 5452 KB Output is correct
21 Correct 4 ms 2516 KB Output is correct
22 Correct 13 ms 5324 KB Output is correct
23 Correct 15 ms 5196 KB Output is correct
24 Correct 20 ms 5380 KB Output is correct
25 Correct 18 ms 5452 KB Output is correct
26 Correct 21 ms 5464 KB Output is correct
27 Correct 16 ms 5400 KB Output is correct
28 Correct 17 ms 5448 KB Output is correct
29 Correct 22 ms 5324 KB Output is correct
30 Correct 17 ms 5324 KB Output is correct
31 Correct 19 ms 5328 KB Output is correct
32 Correct 16 ms 5324 KB Output is correct
33 Correct 27 ms 5456 KB Output is correct
34 Correct 28 ms 5400 KB Output is correct
35 Correct 20 ms 4808 KB Output is correct
36 Correct 10 ms 3664 KB Output is correct
37 Correct 28 ms 5972 KB Output is correct
38 Correct 31 ms 6220 KB Output is correct
39 Correct 29 ms 6276 KB Output is correct
40 Correct 31 ms 6224 KB Output is correct
41 Correct 39 ms 6224 KB Output is correct
42 Correct 23 ms 6076 KB Output is correct
43 Correct 19 ms 6096 KB Output is correct
44 Correct 18 ms 6136 KB Output is correct
45 Correct 31 ms 6224 KB Output is correct
46 Correct 31 ms 6220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 2 ms 1804 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 3 ms 1880 KB Output is correct
16 Correct 2 ms 2072 KB Output is correct
17 Correct 8 ms 2896 KB Output is correct
18 Correct 15 ms 5328 KB Output is correct
19 Correct 14 ms 5324 KB Output is correct
20 Correct 15 ms 5452 KB Output is correct
21 Correct 3 ms 2516 KB Output is correct
22 Correct 15 ms 5324 KB Output is correct
23 Correct 14 ms 5184 KB Output is correct
24 Correct 18 ms 5328 KB Output is correct
25 Correct 20 ms 5440 KB Output is correct
26 Correct 15 ms 5452 KB Output is correct
27 Correct 16 ms 5452 KB Output is correct
28 Correct 16 ms 5408 KB Output is correct
29 Correct 23 ms 5312 KB Output is correct
30 Correct 17 ms 5312 KB Output is correct
31 Correct 20 ms 5316 KB Output is correct
32 Correct 16 ms 5320 KB Output is correct
33 Correct 27 ms 5456 KB Output is correct
34 Correct 29 ms 5452 KB Output is correct
35 Correct 26 ms 4816 KB Output is correct
36 Correct 14 ms 3664 KB Output is correct
37 Correct 31 ms 5968 KB Output is correct
38 Correct 29 ms 6292 KB Output is correct
39 Correct 28 ms 6220 KB Output is correct
40 Correct 30 ms 6224 KB Output is correct
41 Correct 29 ms 6228 KB Output is correct
42 Correct 18 ms 6124 KB Output is correct
43 Correct 20 ms 6028 KB Output is correct
44 Correct 18 ms 6136 KB Output is correct
45 Correct 32 ms 6224 KB Output is correct
46 Correct 32 ms 6224 KB Output is correct
47 Correct 211 ms 31812 KB Output is correct
48 Correct 185 ms 40608 KB Output is correct
49 Correct 234 ms 59976 KB Output is correct
50 Correct 233 ms 60660 KB Output is correct
51 Correct 301 ms 61896 KB Output is correct
52 Correct 317 ms 61816 KB Output is correct
53 Correct 264 ms 61856 KB Output is correct
54 Correct 244 ms 60728 KB Output is correct
55 Correct 246 ms 60660 KB Output is correct
56 Correct 281 ms 62152 KB Output is correct
57 Correct 361 ms 60828 KB Output is correct
58 Incorrect 88 ms 61368 KB Output isn't correct
59 Halted 0 ms 0 KB -