Submission #208786

# Submission time Handle Problem Language Result Execution time Memory
208786 2020-03-12T07:49:30 Z YJU Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 133896 KB
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=3e4+5;
const ll INF=(1LL<<30);
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
 
 
ll n,m,b[N],p[N],x,y,dis[N];
vector<ll> P[N],tmp;
vector<pll> v[N];
vector<vector<ll> > lis;
priority_queue<pll,vector<pll>,greater<pll> > pq;
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP(i,m){
		cin>>b[i]>>p[i];
		P[p[i]].pb(b[i]);
	}
	for(ll step=1;step<N;++step){
		if(!SZ(P[step]))continue;
		lis.clear();lis.resize(step);
		tmp.clear();
		for(auto i:P[step]){
			lis[i%step].pb(i);
			tmp.pb(i%step);
		}
		sort(tmp.begin(),tmp.end());
		tmp.resize(unique(tmp.begin(),tmp.end())-tmp.begin());
		for(auto i:tmp){
			sort(lis[i].begin(),lis[i].end());
			for(ll j=1;j<SZ(lis[i]);++j){
				x=lis[i][j-1],y=lis[i][j];
				for(ll ii=x;ii<=y;ii+=step){
					v[x].pb(mp(ii,(ii-x)/step));
					v[y].pb(mp(ii,(y-ii)/step));
				}
			}
			for(ll ii=lis[i].back();ii<N;ii+=step)x=lis[i].back(),v[x].pb(mp(ii,(ii-x)/step));
			for(ll ii=lis[i][0];ii>=0;ii-=step)x=lis[i][0],v[x].pb(mp(ii,(x-ii)/step));
		}
	}
	REP(i,N)dis[i]=INF;
	pq.push(mp(0,b[0]));
	while(SZ(pq)){
		x=pq.top().Y;y=pq.top().X;pq.pop();
		if(dis[x]<=y)continue;
		dis[x]=y;
		for(auto j:v[x])if(dis[j.X]>dis[x]+j.Y)pq.push(mp(dis[x]+j.Y,j.X));
	}
	cout<<(dis[b[1]]==INF?-1:dis[b[1]])<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2804 KB Output is correct
2 Correct 9 ms 2552 KB Output is correct
3 Correct 7 ms 2168 KB Output is correct
4 Correct 6 ms 2040 KB Output is correct
5 Correct 12 ms 2840 KB Output is correct
6 Correct 13 ms 2932 KB Output is correct
7 Correct 9 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2932 KB Output is correct
2 Correct 9 ms 2552 KB Output is correct
3 Correct 6 ms 2168 KB Output is correct
4 Correct 6 ms 2044 KB Output is correct
5 Correct 12 ms 2840 KB Output is correct
6 Correct 13 ms 2932 KB Output is correct
7 Correct 9 ms 2424 KB Output is correct
8 Correct 13 ms 2940 KB Output is correct
9 Correct 27 ms 4084 KB Output is correct
10 Correct 103 ms 10272 KB Output is correct
11 Correct 326 ms 30920 KB Output is correct
12 Correct 20 ms 3872 KB Output is correct
13 Correct 9 ms 2580 KB Output is correct
14 Correct 496 ms 35276 KB Output is correct
15 Correct 480 ms 35276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2928 KB Output is correct
2 Correct 9 ms 2552 KB Output is correct
3 Correct 7 ms 2168 KB Output is correct
4 Correct 6 ms 2040 KB Output is correct
5 Correct 12 ms 2840 KB Output is correct
6 Correct 13 ms 2932 KB Output is correct
7 Correct 10 ms 2424 KB Output is correct
8 Correct 14 ms 2940 KB Output is correct
9 Correct 27 ms 4080 KB Output is correct
10 Correct 106 ms 10276 KB Output is correct
11 Correct 321 ms 30920 KB Output is correct
12 Correct 20 ms 3876 KB Output is correct
13 Correct 9 ms 2580 KB Output is correct
14 Correct 482 ms 35568 KB Output is correct
15 Correct 502 ms 35404 KB Output is correct
16 Correct 15 ms 7160 KB Output is correct
17 Correct 142 ms 16232 KB Output is correct
18 Correct 11 ms 3320 KB Output is correct
19 Correct 9 ms 2812 KB Output is correct
20 Correct 9 ms 2552 KB Output is correct
21 Correct 11 ms 3448 KB Output is correct
22 Correct 10 ms 3064 KB Output is correct
23 Correct 28 ms 4500 KB Output is correct
24 Correct 48 ms 6416 KB Output is correct
25 Correct 22 ms 3636 KB Output is correct
26 Correct 25 ms 4216 KB Output is correct
27 Correct 21 ms 3716 KB Output is correct
28 Correct 19 ms 5496 KB Output is correct
29 Correct 230 ms 18016 KB Output is correct
30 Correct 54 ms 6784 KB Output is correct
31 Correct 111 ms 10700 KB Output is correct
32 Correct 76 ms 9208 KB Output is correct
33 Correct 487 ms 35132 KB Output is correct
34 Correct 490 ms 35012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2808 KB Output is correct
2 Correct 9 ms 2552 KB Output is correct
3 Correct 7 ms 2168 KB Output is correct
4 Correct 7 ms 2040 KB Output is correct
5 Correct 11 ms 2840 KB Output is correct
6 Correct 13 ms 2932 KB Output is correct
7 Correct 9 ms 2424 KB Output is correct
8 Correct 13 ms 2940 KB Output is correct
9 Correct 27 ms 4080 KB Output is correct
10 Correct 104 ms 10276 KB Output is correct
11 Correct 325 ms 30924 KB Output is correct
12 Correct 21 ms 3872 KB Output is correct
13 Correct 10 ms 2580 KB Output is correct
14 Correct 495 ms 35276 KB Output is correct
15 Correct 490 ms 35272 KB Output is correct
16 Correct 16 ms 7284 KB Output is correct
17 Correct 143 ms 16104 KB Output is correct
18 Correct 11 ms 3192 KB Output is correct
19 Correct 9 ms 2808 KB Output is correct
20 Correct 10 ms 2552 KB Output is correct
21 Correct 12 ms 3448 KB Output is correct
22 Correct 10 ms 3064 KB Output is correct
23 Correct 29 ms 4500 KB Output is correct
24 Correct 47 ms 6288 KB Output is correct
25 Correct 23 ms 3636 KB Output is correct
26 Correct 24 ms 4212 KB Output is correct
27 Correct 20 ms 3716 KB Output is correct
28 Correct 18 ms 5496 KB Output is correct
29 Correct 224 ms 17956 KB Output is correct
30 Correct 56 ms 6788 KB Output is correct
31 Correct 109 ms 10696 KB Output is correct
32 Correct 76 ms 9208 KB Output is correct
33 Correct 484 ms 35264 KB Output is correct
34 Correct 492 ms 35012 KB Output is correct
35 Correct 609 ms 42540 KB Output is correct
36 Correct 119 ms 11400 KB Output is correct
37 Correct 827 ms 63332 KB Output is correct
38 Correct 721 ms 62916 KB Output is correct
39 Correct 740 ms 62660 KB Output is correct
40 Correct 739 ms 62404 KB Output is correct
41 Correct 742 ms 62920 KB Output is correct
42 Correct 30 ms 5124 KB Output is correct
43 Correct 28 ms 4720 KB Output is correct
44 Correct 17 ms 3764 KB Output is correct
45 Execution timed out 1103 ms 133896 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2804 KB Output is correct
2 Correct 10 ms 2552 KB Output is correct
3 Correct 7 ms 2168 KB Output is correct
4 Correct 6 ms 2040 KB Output is correct
5 Correct 11 ms 2840 KB Output is correct
6 Correct 13 ms 2932 KB Output is correct
7 Correct 9 ms 2552 KB Output is correct
8 Correct 13 ms 2940 KB Output is correct
9 Correct 28 ms 4080 KB Output is correct
10 Correct 102 ms 10276 KB Output is correct
11 Correct 331 ms 30920 KB Output is correct
12 Correct 20 ms 3876 KB Output is correct
13 Correct 9 ms 2580 KB Output is correct
14 Correct 491 ms 35272 KB Output is correct
15 Correct 482 ms 35400 KB Output is correct
16 Correct 15 ms 7156 KB Output is correct
17 Correct 141 ms 16244 KB Output is correct
18 Correct 11 ms 3192 KB Output is correct
19 Correct 9 ms 2808 KB Output is correct
20 Correct 10 ms 2552 KB Output is correct
21 Correct 12 ms 3448 KB Output is correct
22 Correct 10 ms 3064 KB Output is correct
23 Correct 27 ms 4500 KB Output is correct
24 Correct 47 ms 6288 KB Output is correct
25 Correct 26 ms 3636 KB Output is correct
26 Correct 24 ms 4220 KB Output is correct
27 Correct 21 ms 3720 KB Output is correct
28 Correct 18 ms 5500 KB Output is correct
29 Correct 222 ms 18016 KB Output is correct
30 Correct 54 ms 6784 KB Output is correct
31 Correct 110 ms 10828 KB Output is correct
32 Correct 75 ms 9208 KB Output is correct
33 Correct 478 ms 35264 KB Output is correct
34 Correct 486 ms 35264 KB Output is correct
35 Correct 617 ms 42492 KB Output is correct
36 Correct 113 ms 11400 KB Output is correct
37 Correct 838 ms 63376 KB Output is correct
38 Correct 744 ms 62928 KB Output is correct
39 Correct 737 ms 62660 KB Output is correct
40 Correct 730 ms 62404 KB Output is correct
41 Correct 748 ms 62920 KB Output is correct
42 Correct 32 ms 5124 KB Output is correct
43 Correct 27 ms 4720 KB Output is correct
44 Correct 16 ms 3764 KB Output is correct
45 Execution timed out 1101 ms 133896 KB Time limit exceeded
46 Halted 0 ms 0 KB -