Submission #45209

# Submission time Handle Problem Language Result Execution time Memory
45209 2018-04-11T21:15:54 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]));
			}	
		}		
	}




	/*
	deque<pii> dk;
	dk.pb(mp(1,0));
	while(dk.size()){
		ll v=dk.front().S;
		ll w=dk.front().F;
		dk.pop_front();
		if(h[v]==0){
			h[v]=w;
			for(auto e:ger[v]){
				if(e.S){
					dk.pb(mp(w+1,e.F));
				}else{
					dk.push_front(mp(w,e.F));
				}
			}
		}
	}*/
	
	   set<pii> st;
	   set<pii> :: iterator it;
	   st.insert(mp(1,0));
	   while(st.size()){
	   it=st.begin();
	   ll v=(*it).S;
	   ll w=(*it).F;
	   st.erase(it);
	   if(h[v]==0){
	   h[v]=w;
	   for(auto e:ger[v]){
	   st.insert(mp(e.S+w,e.F));
	   }
	   }
	   }
	if(h[1]==0){
		cout<<-1;
	}else{
		cout<<h[1]-1;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 141944 KB Output is correct
2 Correct 152 ms 142164 KB Output is correct
3 Correct 112 ms 142164 KB Output is correct
4 Correct 108 ms 142188 KB Output is correct
5 Correct 108 ms 142236 KB Output is correct
6 Correct 109 ms 142344 KB Output is correct
7 Correct 110 ms 142344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 142344 KB Output is correct
2 Correct 111 ms 142344 KB Output is correct
3 Correct 110 ms 142400 KB Output is correct
4 Correct 112 ms 142416 KB Output is correct
5 Correct 128 ms 142416 KB Output is correct
6 Correct 111 ms 142416 KB Output is correct
7 Correct 110 ms 142416 KB Output is correct
8 Correct 129 ms 142444 KB Output is correct
9 Correct 107 ms 142676 KB Output is correct
10 Correct 111 ms 142956 KB Output is correct
11 Correct 114 ms 143180 KB Output is correct
12 Correct 131 ms 143212 KB Output is correct
13 Correct 111 ms 143212 KB Output is correct
14 Correct 113 ms 143212 KB Output is correct
15 Correct 113 ms 143228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 143228 KB Output is correct
2 Correct 115 ms 143228 KB Output is correct
3 Correct 110 ms 143228 KB Output is correct
4 Correct 109 ms 143228 KB Output is correct
5 Correct 113 ms 143228 KB Output is correct
6 Correct 117 ms 143228 KB Output is correct
7 Correct 122 ms 143228 KB Output is correct
8 Correct 111 ms 143228 KB Output is correct
9 Correct 113 ms 143228 KB Output is correct
10 Correct 119 ms 143228 KB Output is correct
11 Correct 116 ms 143228 KB Output is correct
12 Correct 120 ms 143228 KB Output is correct
13 Correct 115 ms 143228 KB Output is correct
14 Correct 125 ms 143228 KB Output is correct
15 Correct 120 ms 143228 KB Output is correct
16 Correct 124 ms 143740 KB Output is correct
17 Correct 135 ms 147708 KB Output is correct
18 Correct 151 ms 153176 KB Output is correct
19 Correct 163 ms 154784 KB Output is correct
20 Correct 173 ms 154960 KB Output is correct
21 Correct 126 ms 154960 KB Output is correct
22 Correct 158 ms 154960 KB Output is correct
23 Correct 274 ms 154960 KB Output is correct
24 Correct 158 ms 155328 KB Output is correct
25 Correct 159 ms 155328 KB Output is correct
26 Correct 157 ms 156040 KB Output is correct
27 Correct 156 ms 156040 KB Output is correct
28 Correct 160 ms 156040 KB Output is correct
29 Correct 182 ms 156040 KB Output is correct
30 Correct 163 ms 156040 KB Output is correct
31 Correct 164 ms 156040 KB Output is correct
32 Correct 164 ms 156040 KB Output is correct
33 Correct 187 ms 156040 KB Output is correct
34 Correct 194 ms 156040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 156040 KB Output is correct
2 Correct 108 ms 156040 KB Output is correct
3 Correct 127 ms 156040 KB Output is correct
4 Correct 109 ms 156040 KB Output is correct
5 Correct 112 ms 156040 KB Output is correct
6 Correct 117 ms 156040 KB Output is correct
7 Correct 115 ms 156040 KB Output is correct
8 Correct 120 ms 156040 KB Output is correct
9 Correct 110 ms 156040 KB Output is correct
10 Correct 125 ms 156040 KB Output is correct
11 Correct 113 ms 156040 KB Output is correct
12 Correct 127 ms 156040 KB Output is correct
13 Correct 147 ms 156040 KB Output is correct
14 Correct 140 ms 156040 KB Output is correct
15 Correct 133 ms 156040 KB Output is correct
16 Correct 130 ms 156040 KB Output is correct
17 Correct 193 ms 156040 KB Output is correct
18 Correct 175 ms 156040 KB Output is correct
19 Correct 165 ms 156040 KB Output is correct
20 Correct 169 ms 156040 KB Output is correct
21 Correct 120 ms 156040 KB Output is correct
22 Correct 153 ms 156040 KB Output is correct
23 Correct 155 ms 156040 KB Output is correct
24 Correct 166 ms 156040 KB Output is correct
25 Correct 164 ms 156040 KB Output is correct
26 Correct 172 ms 156248 KB Output is correct
27 Correct 164 ms 156248 KB Output is correct
28 Correct 207 ms 156336 KB Output is correct
29 Correct 217 ms 156336 KB Output is correct
30 Correct 186 ms 156336 KB Output is correct
31 Correct 170 ms 156336 KB Output is correct
32 Correct 172 ms 156336 KB Output is correct
33 Correct 194 ms 156336 KB Output is correct
34 Correct 198 ms 156336 KB Output is correct
35 Correct 208 ms 156336 KB Output is correct
36 Correct 146 ms 156336 KB Output is correct
37 Correct 268 ms 159804 KB Output is correct
38 Correct 248 ms 160556 KB Output is correct
39 Correct 252 ms 160760 KB Output is correct
40 Correct 256 ms 161208 KB Output is correct
41 Correct 249 ms 161344 KB Output is correct
42 Correct 203 ms 161344 KB Output is correct
43 Correct 186 ms 161344 KB Output is correct
44 Correct 189 ms 161344 KB Output is correct
45 Correct 306 ms 164152 KB Output is correct
46 Correct 306 ms 164416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 164416 KB Output is correct
2 Correct 117 ms 164416 KB Output is correct
3 Correct 112 ms 164416 KB Output is correct
4 Correct 113 ms 164416 KB Output is correct
5 Correct 109 ms 164416 KB Output is correct
6 Correct 110 ms 164416 KB Output is correct
7 Correct 113 ms 164416 KB Output is correct
8 Correct 112 ms 164416 KB Output is correct
9 Correct 145 ms 164416 KB Output is correct
10 Correct 116 ms 164416 KB Output is correct
11 Correct 118 ms 164416 KB Output is correct
12 Correct 112 ms 164416 KB Output is correct
13 Correct 113 ms 164416 KB Output is correct
14 Correct 113 ms 164416 KB Output is correct
15 Correct 118 ms 164416 KB Output is correct
16 Correct 115 ms 164416 KB Output is correct
17 Correct 136 ms 164416 KB Output is correct
18 Correct 151 ms 164416 KB Output is correct
19 Correct 155 ms 164416 KB Output is correct
20 Correct 170 ms 164416 KB Output is correct
21 Correct 120 ms 164416 KB Output is correct
22 Correct 152 ms 164416 KB Output is correct
23 Correct 152 ms 164416 KB Output is correct
24 Correct 158 ms 164416 KB Output is correct
25 Correct 156 ms 164416 KB Output is correct
26 Correct 158 ms 164416 KB Output is correct
27 Correct 158 ms 164416 KB Output is correct
28 Correct 159 ms 164416 KB Output is correct
29 Correct 187 ms 164416 KB Output is correct
30 Correct 158 ms 164416 KB Output is correct
31 Correct 169 ms 164416 KB Output is correct
32 Correct 164 ms 164416 KB Output is correct
33 Correct 196 ms 164416 KB Output is correct
34 Correct 190 ms 164416 KB Output is correct
35 Correct 209 ms 164416 KB Output is correct
36 Correct 145 ms 164416 KB Output is correct
37 Correct 246 ms 164416 KB Output is correct
38 Correct 267 ms 164416 KB Output is correct
39 Correct 252 ms 164416 KB Output is correct
40 Correct 252 ms 164416 KB Output is correct
41 Correct 261 ms 164416 KB Output is correct
42 Correct 193 ms 164416 KB Output is correct
43 Correct 189 ms 164416 KB Output is correct
44 Correct 211 ms 164416 KB Output is correct
45 Correct 308 ms 166836 KB Output is correct
46 Correct 324 ms 167068 KB Output is correct
47 Correct 878 ms 249396 KB Output is correct
48 Execution timed out 1110 ms 262144 KB Time limit exceeded
49 Halted 0 ms 0 KB -