Submission #527445

# Submission time Handle Problem Language Result Execution time Memory
527445 2022-02-17T12:30:33 Z Koosha_mv Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 110924 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

const int N=50000,S=125;

int m,n,pos[N],p[N],dist[N][S];
vector<int> vec[N];
set<pair<int,pair<int,int>>> 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]=N;
	dist[pos[0]][0]=0;
	f(i,0,n) f(j,0,S) st.insert({dist[i][j],{i,j}});
	while(st.size()){
		int x=(*st.begin()).S.F,p=(*st.begin()).S.S;
		if(dist[x][p]==N) break;
		//cout<<endl;
		//eror(dist[2][0]);
		//cout<<x<<" "<<p<<" -> "<<dist[x][p]<<endl;
		st.erase(*st.begin());
		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);
				st.erase({dist[x+p][0],{x+p,0}});
				dist[x+p][0]=dist[x][p]+1;
				st.insert({dist[x+p][0],{x+p,0}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][0]){
				st.erase({dist[x-p][0],{x-p,0}});
				dist[x-p][0]=dist[x][p]+1;
				st.insert({dist[x-p][0],{x-p,0}});
			}
			
			if(x+p<n && dist[x][p]+1<dist[x+p][p]){
				st.erase({dist[x+p][p],{x+p,p}});
				dist[x+p][p]=dist[x][p]+1;
				st.insert({dist[x+p][p],{x+p,p}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][p]){
				st.erase({dist[x-p][p],{x-p,p}});
				dist[x-p][p]=dist[x][p]+1;
				st.insert({dist[x-p][p],{x-p,p}});
			}
			continue ;
		}
		for(auto u : vec[x]){
			if(u<S){
				if(dist[x][u]<=dist[x][p]) continue ;
				st.erase({dist[x][u],{x,u}});
				dist[x][u]=dist[x][p];
				st.insert({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]){
						st.erase({dist[i][p],{i,p}});
						dist[i][p]=dist[x][p]+abs(x-i)/u;
						st.insert({dist[i][p],{i,p}});
					}
				}
			}
		}
	}
	cout<<(dist[pos[1]][0]==N ? -1 : dist[pos[1]][0]);
}

Compilation message

skyscraper.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | 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 7 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 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 2 ms 1740 KB Output is correct
9 Correct 2 ms 1996 KB Output is correct
10 Correct 4 ms 2380 KB Output is correct
11 Correct 5 ms 2380 KB Output is correct
12 Correct 4 ms 2380 KB Output is correct
13 Correct 4 ms 2380 KB Output is correct
14 Correct 5 ms 2380 KB Output is correct
15 Correct 5 ms 2380 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 3 ms 1740 KB Output is correct
9 Correct 2 ms 1996 KB Output is correct
10 Correct 5 ms 2380 KB Output is correct
11 Correct 6 ms 2448 KB Output is correct
12 Correct 4 ms 2380 KB Output is correct
13 Correct 3 ms 2380 KB Output is correct
14 Correct 6 ms 2380 KB Output is correct
15 Correct 6 ms 2380 KB Output is correct
16 Correct 6 ms 3276 KB Output is correct
17 Correct 31 ms 8064 KB Output is correct
18 Correct 62 ms 16944 KB Output is correct
19 Correct 80 ms 19004 KB Output is correct
20 Correct 76 ms 19132 KB Output is correct
21 Correct 15 ms 4960 KB Output is correct
22 Correct 58 ms 17192 KB Output is correct
23 Correct 66 ms 15580 KB Output is correct
24 Correct 76 ms 18296 KB Output is correct
25 Correct 77 ms 19200 KB Output is correct
26 Correct 84 ms 19120 KB Output is correct
27 Correct 75 ms 19108 KB Output is correct
28 Correct 78 ms 19168 KB Output is correct
29 Correct 107 ms 19120 KB Output is correct
30 Correct 83 ms 19164 KB Output is correct
31 Correct 92 ms 19088 KB Output is correct
32 Correct 86 ms 19052 KB Output is correct
33 Correct 135 ms 19152 KB Output is correct
34 Correct 149 ms 19272 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 1740 KB Output is correct
9 Correct 2 ms 1996 KB Output is correct
10 Correct 6 ms 2380 KB Output is correct
11 Correct 6 ms 2380 KB Output is correct
12 Correct 4 ms 2332 KB Output is correct
13 Correct 3 ms 2380 KB Output is correct
14 Correct 8 ms 2444 KB Output is correct
15 Correct 6 ms 2324 KB Output is correct
16 Correct 6 ms 3276 KB Output is correct
17 Correct 31 ms 8060 KB Output is correct
18 Correct 59 ms 16792 KB Output is correct
19 Correct 68 ms 19012 KB Output is correct
20 Correct 64 ms 19148 KB Output is correct
21 Correct 13 ms 4932 KB Output is correct
22 Correct 59 ms 17132 KB Output is correct
23 Correct 60 ms 15576 KB Output is correct
24 Correct 77 ms 18384 KB Output is correct
25 Correct 72 ms 19148 KB Output is correct
26 Correct 76 ms 19116 KB Output is correct
27 Correct 83 ms 19132 KB Output is correct
28 Correct 82 ms 19140 KB Output is correct
29 Correct 114 ms 19120 KB Output is correct
30 Correct 79 ms 19012 KB Output is correct
31 Correct 91 ms 19000 KB Output is correct
32 Correct 87 ms 19024 KB Output is correct
33 Correct 136 ms 19052 KB Output is correct
34 Correct 136 ms 19144 KB Output is correct
35 Correct 95 ms 14844 KB Output is correct
36 Correct 57 ms 11200 KB Output is correct
37 Correct 168 ms 19008 KB Output is correct
38 Correct 150 ms 19916 KB Output is correct
39 Correct 171 ms 20036 KB Output is correct
40 Correct 157 ms 19892 KB Output is correct
41 Correct 153 ms 19932 KB Output is correct
42 Correct 81 ms 19700 KB Output is correct
43 Correct 73 ms 19692 KB Output is correct
44 Correct 91 ms 19768 KB Output is correct
45 Correct 185 ms 19816 KB Output is correct
46 Correct 191 ms 19908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 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 1740 KB Output is correct
9 Correct 2 ms 1996 KB Output is correct
10 Correct 4 ms 2380 KB Output is correct
11 Correct 8 ms 2380 KB Output is correct
12 Correct 4 ms 2380 KB Output is correct
13 Correct 4 ms 2380 KB Output is correct
14 Correct 6 ms 2408 KB Output is correct
15 Correct 9 ms 2380 KB Output is correct
16 Correct 7 ms 3172 KB Output is correct
17 Correct 42 ms 8012 KB Output is correct
18 Correct 66 ms 16928 KB Output is correct
19 Correct 75 ms 19084 KB Output is correct
20 Correct 78 ms 19208 KB Output is correct
21 Correct 17 ms 5000 KB Output is correct
22 Correct 59 ms 17120 KB Output is correct
23 Correct 68 ms 15572 KB Output is correct
24 Correct 75 ms 18236 KB Output is correct
25 Correct 75 ms 19144 KB Output is correct
26 Correct 77 ms 19076 KB Output is correct
27 Correct 70 ms 19156 KB Output is correct
28 Correct 86 ms 19068 KB Output is correct
29 Correct 111 ms 19064 KB Output is correct
30 Correct 82 ms 18980 KB Output is correct
31 Correct 105 ms 19136 KB Output is correct
32 Correct 91 ms 19052 KB Output is correct
33 Correct 179 ms 19156 KB Output is correct
34 Correct 137 ms 19156 KB Output is correct
35 Correct 109 ms 14848 KB Output is correct
36 Correct 45 ms 11188 KB Output is correct
37 Correct 208 ms 19108 KB Output is correct
38 Correct 147 ms 19860 KB Output is correct
39 Correct 153 ms 19936 KB Output is correct
40 Correct 171 ms 19996 KB Output is correct
41 Correct 160 ms 19872 KB Output is correct
42 Correct 83 ms 19732 KB Output is correct
43 Correct 79 ms 19808 KB Output is correct
44 Correct 83 ms 19792 KB Output is correct
45 Correct 199 ms 19904 KB Output is correct
46 Correct 183 ms 19788 KB Output is correct
47 Execution timed out 1089 ms 110924 KB Time limit exceeded
48 Halted 0 ms 0 KB -