Submission #45211

# Submission time Handle Problem Language Result Execution time Memory
45211 2018-04-11T21:20:28 Z ckodser Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 262144 KB
#include<bits/stdc++.h>

#define ll	int 
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=3e4+10;
const ll mod=1e9+7;
const ll inf=1e9+500;
const ll rad=100;
const ll maxm=maxn*(rad)*2+50;

ll b[maxn];
ll p[maxn];
vector<ll> vec[maxn];

vector<pair<ll,short> > ger[maxm];
ll h[maxm];


int main(){

	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		cin>>b[i]>>p[i];
		vec[b[i]].pb(i);
	}
	for(ll i=0;i<n;i++){
		for(auto v:vec[i]){
			ger[i+m].pb(mp(v,0));
		}
	}	


	for(ll j=1;j<rad;j++){
		for(ll i=0;i<n;i++){
			ger[m+j*n+i].pb(mp(i+m,0));
			if(i>=j){
				ger[m+j*n+i].pb(mp(m+j*n+i-j,1));
			}
		}
	}
	for(ll j=1;j<rad;j++){
		for(ll i=0;i<n;i++){
			ll v=m+rad*n+(j-1)*n+i;
			ger[v].pb(mp(i+m,0));
			if(i+j<n){
				ger[v].pb(mp(v+j,1));
			}
		}
	}
	for(ll i=0;i<m;i++){
		if(p[i]<rad){
			ll v=b[i];
			ger[i].pb(mp(m+n*p[i]+v,0));
			ger[i].pb(mp(m+rad*n+(p[i]-1)*n+v,0));
		}
	}



	for(ll i=0;i<m;i++){
		if(p[i]>=rad){
			for(ll j=b[i];j<n;j+=p[i]){
				ger[i].pb(mp(j+m,(j-b[i])/p[i]));
			}
			for(ll j=b[i]-p[i];j>=0;j-=p[i]){
				ger[i].pb(mp(j+m,(b[i]-j)/p[i]));
			}	
		}		
	}




	priority_queue<pii> st;
	st.push(mp(-1,0));
	while(st.size()){
		ll v=(st.top()).S;
		ll w=(st.top()).F;
		st.pop();
		if(h[v]==0){
			h[v]=-w;
			for(auto e:ger[v]){
				st.push(mp(w-e.S,e.F));
			}
		}
	}
	if(h[1]==0){
		cout<<-1;
	}else{
		cout<<h[1]-1;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 108 ms 141944 KB Output is correct
2 Correct 109 ms 142084 KB Output is correct
3 Correct 111 ms 142264 KB Output is correct
4 Correct 107 ms 142264 KB Output is correct
5 Correct 111 ms 142332 KB Output is correct
6 Correct 108 ms 142332 KB Output is correct
7 Correct 110 ms 142356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 142356 KB Output is correct
2 Correct 111 ms 142356 KB Output is correct
3 Correct 109 ms 142356 KB Output is correct
4 Correct 123 ms 142356 KB Output is correct
5 Correct 106 ms 142464 KB Output is correct
6 Correct 109 ms 142464 KB Output is correct
7 Correct 107 ms 142464 KB Output is correct
8 Correct 110 ms 142464 KB Output is correct
9 Correct 110 ms 142700 KB Output is correct
10 Correct 112 ms 143100 KB Output is correct
11 Correct 116 ms 143100 KB Output is correct
12 Correct 111 ms 143228 KB Output is correct
13 Correct 112 ms 143228 KB Output is correct
14 Correct 120 ms 143228 KB Output is correct
15 Correct 124 ms 143228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 143228 KB Output is correct
2 Correct 114 ms 143228 KB Output is correct
3 Correct 109 ms 143228 KB Output is correct
4 Correct 115 ms 143228 KB Output is correct
5 Correct 110 ms 143228 KB Output is correct
6 Correct 111 ms 143228 KB Output is correct
7 Correct 112 ms 143228 KB Output is correct
8 Correct 118 ms 143228 KB Output is correct
9 Correct 114 ms 143228 KB Output is correct
10 Correct 113 ms 143228 KB Output is correct
11 Correct 128 ms 143228 KB Output is correct
12 Correct 112 ms 143228 KB Output is correct
13 Correct 122 ms 143228 KB Output is correct
14 Correct 112 ms 143228 KB Output is correct
15 Correct 119 ms 143228 KB Output is correct
16 Correct 115 ms 143484 KB Output is correct
17 Correct 149 ms 147644 KB Output is correct
18 Correct 152 ms 153244 KB Output is correct
19 Correct 173 ms 154668 KB Output is correct
20 Correct 159 ms 154900 KB Output is correct
21 Correct 123 ms 154900 KB Output is correct
22 Correct 170 ms 154900 KB Output is correct
23 Correct 154 ms 154900 KB Output is correct
24 Correct 166 ms 155332 KB Output is correct
25 Correct 159 ms 155332 KB Output is correct
26 Correct 166 ms 155880 KB Output is correct
27 Correct 162 ms 155880 KB Output is correct
28 Correct 162 ms 155992 KB Output is correct
29 Correct 170 ms 155992 KB Output is correct
30 Correct 160 ms 155992 KB Output is correct
31 Correct 178 ms 155992 KB Output is correct
32 Correct 167 ms 155992 KB Output is correct
33 Correct 187 ms 155992 KB Output is correct
34 Correct 198 ms 156016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 156016 KB Output is correct
2 Correct 109 ms 156016 KB Output is correct
3 Correct 110 ms 156016 KB Output is correct
4 Correct 109 ms 156016 KB Output is correct
5 Correct 109 ms 156016 KB Output is correct
6 Correct 113 ms 156016 KB Output is correct
7 Correct 108 ms 156016 KB Output is correct
8 Correct 116 ms 156016 KB Output is correct
9 Correct 143 ms 156016 KB Output is correct
10 Correct 111 ms 156016 KB Output is correct
11 Correct 118 ms 156016 KB Output is correct
12 Correct 112 ms 156016 KB Output is correct
13 Correct 124 ms 156016 KB Output is correct
14 Correct 113 ms 156016 KB Output is correct
15 Correct 115 ms 156016 KB Output is correct
16 Correct 120 ms 156016 KB Output is correct
17 Correct 132 ms 156016 KB Output is correct
18 Correct 163 ms 156016 KB Output is correct
19 Correct 167 ms 156016 KB Output is correct
20 Correct 158 ms 156016 KB Output is correct
21 Correct 119 ms 156016 KB Output is correct
22 Correct 175 ms 156016 KB Output is correct
23 Correct 148 ms 156016 KB Output is correct
24 Correct 159 ms 156016 KB Output is correct
25 Correct 164 ms 156016 KB Output is correct
26 Correct 331 ms 156164 KB Output is correct
27 Correct 181 ms 156164 KB Output is correct
28 Correct 167 ms 156188 KB Output is correct
29 Correct 186 ms 156188 KB Output is correct
30 Correct 199 ms 156188 KB Output is correct
31 Correct 191 ms 156188 KB Output is correct
32 Correct 182 ms 156188 KB Output is correct
33 Correct 213 ms 156188 KB Output is correct
34 Correct 203 ms 156252 KB Output is correct
35 Correct 255 ms 156252 KB Output is correct
36 Correct 158 ms 156252 KB Output is correct
37 Correct 300 ms 159296 KB Output is correct
38 Correct 270 ms 160392 KB Output is correct
39 Correct 256 ms 160560 KB Output is correct
40 Correct 309 ms 160820 KB Output is correct
41 Correct 291 ms 161056 KB Output is correct
42 Correct 215 ms 161056 KB Output is correct
43 Correct 219 ms 161056 KB Output is correct
44 Correct 218 ms 161056 KB Output is correct
45 Correct 340 ms 167276 KB Output is correct
46 Correct 363 ms 167420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 167420 KB Output is correct
2 Correct 136 ms 167420 KB Output is correct
3 Correct 133 ms 167420 KB Output is correct
4 Correct 125 ms 167420 KB Output is correct
5 Correct 139 ms 167420 KB Output is correct
6 Correct 135 ms 167420 KB Output is correct
7 Correct 126 ms 167420 KB Output is correct
8 Correct 124 ms 167420 KB Output is correct
9 Correct 125 ms 167420 KB Output is correct
10 Correct 138 ms 167420 KB Output is correct
11 Correct 135 ms 167420 KB Output is correct
12 Correct 147 ms 167420 KB Output is correct
13 Correct 126 ms 167420 KB Output is correct
14 Correct 136 ms 167420 KB Output is correct
15 Correct 135 ms 167420 KB Output is correct
16 Correct 131 ms 167420 KB Output is correct
17 Correct 146 ms 167420 KB Output is correct
18 Correct 173 ms 167420 KB Output is correct
19 Correct 168 ms 167420 KB Output is correct
20 Correct 169 ms 167420 KB Output is correct
21 Correct 123 ms 167420 KB Output is correct
22 Correct 164 ms 167420 KB Output is correct
23 Correct 165 ms 167420 KB Output is correct
24 Correct 173 ms 167420 KB Output is correct
25 Correct 170 ms 167420 KB Output is correct
26 Correct 184 ms 167420 KB Output is correct
27 Correct 174 ms 167420 KB Output is correct
28 Correct 170 ms 167420 KB Output is correct
29 Correct 203 ms 167420 KB Output is correct
30 Correct 173 ms 167420 KB Output is correct
31 Correct 179 ms 167420 KB Output is correct
32 Correct 192 ms 167420 KB Output is correct
33 Correct 212 ms 167420 KB Output is correct
34 Correct 209 ms 167420 KB Output is correct
35 Correct 208 ms 167420 KB Output is correct
36 Correct 145 ms 167420 KB Output is correct
37 Correct 249 ms 167420 KB Output is correct
38 Correct 259 ms 167420 KB Output is correct
39 Correct 252 ms 167420 KB Output is correct
40 Correct 272 ms 167420 KB Output is correct
41 Correct 290 ms 167420 KB Output is correct
42 Correct 214 ms 167420 KB Output is correct
43 Correct 202 ms 167420 KB Output is correct
44 Correct 197 ms 167420 KB Output is correct
45 Correct 351 ms 169852 KB Output is correct
46 Correct 355 ms 170144 KB Output is correct
47 Correct 913 ms 242524 KB Output is correct
48 Execution timed out 1100 ms 262144 KB Time limit exceeded
49 Halted 0 ms 0 KB -