Submission #228922

# Submission time Handle Problem Language Result Execution time Memory
228922 2020-05-03T05:53:38 Z alishahali1382 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
489 ms 185464 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int SQ=180, MAXN=180*30000;

int n, m, k, u, v, x, y, t, a, b, ans;
int B[MAXN], P[MAXN];
int dist[MAXN];
bool mark[MAXN];
vector<pii> G[MAXN];
//priority_queue<pii, vector<pii>, greater<pii>> pq;
queue<int> pq;

inline void addedge(int v1, int j1, int v2, int j2, int w){
	G[v1*SQ+j1].pb({v2*SQ+j2, w});
}

inline void upd(int v, int d){
	if (dist[v]>d){
		dist[v]=d;
		if (!mark[v]) pq.push(v);
		mark[v]=1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	memset(dist, 63, sizeof(dist));
	cin>>n>>m;
	for (int i=0; i<m; i++){
		cin>>B[i]>>P[i];
		if (P[i]<SQ) G[B[i]*SQ].pb({B[i]*SQ+P[i], 0});
		else{
			for (int j=1; B[i]-j*P[i]>=0; j++) addedge(B[i], 0, B[i]-P[i]*j, 0, j);
			for (int j=1; B[i]+j*P[i]<n; j++) addedge(B[i], 0, B[i]+P[i]*j, 0, j);
		}
	}
	
	upd(B[0]*SQ, 0);
	while (pq.size()){
		int v=pq.front();//.second;
		pq.pop();
		
		mark[v]=0;
		for (pii p:G[v]) upd(p.first, dist[v]+p.second);
		
		int i=v/SQ, j=v%SQ;
		if (i>=j) upd((i-j)*SQ+j, dist[v]+1);
		if (i+j<n) upd((i+j)*SQ+j, dist[v]+1);
		upd(i*SQ, dist[v]+0);
		
	}
	
	ans=dist[SQ*B[1]];
	if (ans>=inf) ans=-1;
	cout<<ans<<'\n';
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 85 ms 148344 KB Output is correct
2 Correct 82 ms 148344 KB Output is correct
3 Correct 84 ms 148344 KB Output is correct
4 Correct 85 ms 148344 KB Output is correct
5 Correct 86 ms 148472 KB Output is correct
6 Correct 85 ms 148344 KB Output is correct
7 Correct 85 ms 148320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 148344 KB Output is correct
2 Correct 84 ms 148472 KB Output is correct
3 Correct 83 ms 148344 KB Output is correct
4 Correct 82 ms 148344 KB Output is correct
5 Correct 84 ms 148344 KB Output is correct
6 Correct 84 ms 148344 KB Output is correct
7 Correct 84 ms 148344 KB Output is correct
8 Correct 84 ms 148344 KB Output is correct
9 Correct 85 ms 148344 KB Output is correct
10 Correct 83 ms 148344 KB Output is correct
11 Correct 84 ms 148344 KB Output is correct
12 Correct 87 ms 148344 KB Output is correct
13 Correct 84 ms 148344 KB Output is correct
14 Correct 83 ms 148344 KB Output is correct
15 Correct 84 ms 148344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 148344 KB Output is correct
2 Correct 85 ms 148344 KB Output is correct
3 Correct 83 ms 148220 KB Output is correct
4 Correct 84 ms 148344 KB Output is correct
5 Correct 84 ms 148344 KB Output is correct
6 Correct 83 ms 148344 KB Output is correct
7 Correct 85 ms 148344 KB Output is correct
8 Correct 85 ms 148472 KB Output is correct
9 Correct 87 ms 148344 KB Output is correct
10 Correct 85 ms 148344 KB Output is correct
11 Correct 84 ms 148368 KB Output is correct
12 Correct 84 ms 148344 KB Output is correct
13 Correct 84 ms 148344 KB Output is correct
14 Correct 86 ms 148344 KB Output is correct
15 Correct 85 ms 148344 KB Output is correct
16 Correct 85 ms 148348 KB Output is correct
17 Correct 86 ms 148472 KB Output is correct
18 Correct 84 ms 148344 KB Output is correct
19 Correct 87 ms 148344 KB Output is correct
20 Correct 85 ms 148728 KB Output is correct
21 Correct 84 ms 148344 KB Output is correct
22 Correct 84 ms 148348 KB Output is correct
23 Correct 85 ms 148728 KB Output is correct
24 Correct 88 ms 148728 KB Output is correct
25 Correct 83 ms 148728 KB Output is correct
26 Correct 84 ms 148728 KB Output is correct
27 Correct 85 ms 148728 KB Output is correct
28 Correct 88 ms 148856 KB Output is correct
29 Correct 87 ms 148600 KB Output is correct
30 Correct 86 ms 148728 KB Output is correct
31 Correct 88 ms 148600 KB Output is correct
32 Correct 85 ms 148600 KB Output is correct
33 Correct 87 ms 148856 KB Output is correct
34 Correct 89 ms 148728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 148344 KB Output is correct
2 Correct 82 ms 148344 KB Output is correct
3 Correct 85 ms 148344 KB Output is correct
4 Correct 85 ms 148344 KB Output is correct
5 Correct 84 ms 148344 KB Output is correct
6 Correct 83 ms 148344 KB Output is correct
7 Correct 82 ms 148344 KB Output is correct
8 Correct 85 ms 148344 KB Output is correct
9 Correct 85 ms 148344 KB Output is correct
10 Correct 84 ms 148344 KB Output is correct
11 Correct 85 ms 148344 KB Output is correct
12 Correct 83 ms 148344 KB Output is correct
13 Correct 83 ms 148344 KB Output is correct
14 Correct 84 ms 148344 KB Output is correct
15 Correct 83 ms 148344 KB Output is correct
16 Correct 84 ms 148344 KB Output is correct
17 Correct 84 ms 148476 KB Output is correct
18 Correct 86 ms 148344 KB Output is correct
19 Correct 84 ms 148472 KB Output is correct
20 Correct 86 ms 148680 KB Output is correct
21 Correct 91 ms 148344 KB Output is correct
22 Correct 84 ms 148344 KB Output is correct
23 Correct 88 ms 148600 KB Output is correct
24 Correct 84 ms 148728 KB Output is correct
25 Correct 84 ms 148728 KB Output is correct
26 Correct 85 ms 148728 KB Output is correct
27 Correct 84 ms 148856 KB Output is correct
28 Correct 84 ms 148704 KB Output is correct
29 Correct 87 ms 148728 KB Output is correct
30 Correct 85 ms 148600 KB Output is correct
31 Correct 85 ms 148728 KB Output is correct
32 Correct 85 ms 148668 KB Output is correct
33 Correct 89 ms 148728 KB Output is correct
34 Correct 87 ms 148728 KB Output is correct
35 Correct 91 ms 149112 KB Output is correct
36 Correct 87 ms 148600 KB Output is correct
37 Correct 95 ms 149496 KB Output is correct
38 Correct 99 ms 149496 KB Output is correct
39 Correct 96 ms 149496 KB Output is correct
40 Correct 94 ms 149496 KB Output is correct
41 Correct 99 ms 149496 KB Output is correct
42 Correct 91 ms 149368 KB Output is correct
43 Correct 90 ms 149240 KB Output is correct
44 Correct 87 ms 149276 KB Output is correct
45 Correct 105 ms 150648 KB Output is correct
46 Correct 103 ms 150648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 148344 KB Output is correct
2 Correct 88 ms 148344 KB Output is correct
3 Correct 86 ms 148344 KB Output is correct
4 Correct 85 ms 148344 KB Output is correct
5 Correct 85 ms 148344 KB Output is correct
6 Correct 82 ms 148344 KB Output is correct
7 Correct 83 ms 148248 KB Output is correct
8 Correct 83 ms 148344 KB Output is correct
9 Correct 86 ms 148472 KB Output is correct
10 Correct 82 ms 148344 KB Output is correct
11 Correct 83 ms 148344 KB Output is correct
12 Correct 83 ms 148344 KB Output is correct
13 Correct 84 ms 148416 KB Output is correct
14 Correct 83 ms 148344 KB Output is correct
15 Correct 86 ms 148344 KB Output is correct
16 Correct 86 ms 148344 KB Output is correct
17 Correct 87 ms 148472 KB Output is correct
18 Correct 84 ms 148344 KB Output is correct
19 Correct 83 ms 148344 KB Output is correct
20 Correct 87 ms 148728 KB Output is correct
21 Correct 83 ms 148344 KB Output is correct
22 Correct 84 ms 148472 KB Output is correct
23 Correct 83 ms 148600 KB Output is correct
24 Correct 85 ms 148728 KB Output is correct
25 Correct 85 ms 148816 KB Output is correct
26 Correct 87 ms 148728 KB Output is correct
27 Correct 86 ms 148856 KB Output is correct
28 Correct 86 ms 148728 KB Output is correct
29 Correct 87 ms 148632 KB Output is correct
30 Correct 89 ms 148600 KB Output is correct
31 Correct 86 ms 148600 KB Output is correct
32 Correct 84 ms 148600 KB Output is correct
33 Correct 89 ms 148728 KB Output is correct
34 Correct 90 ms 148728 KB Output is correct
35 Correct 96 ms 149240 KB Output is correct
36 Correct 85 ms 148600 KB Output is correct
37 Correct 96 ms 149496 KB Output is correct
38 Correct 97 ms 149496 KB Output is correct
39 Correct 96 ms 149596 KB Output is correct
40 Correct 99 ms 149496 KB Output is correct
41 Correct 98 ms 149680 KB Output is correct
42 Correct 88 ms 149240 KB Output is correct
43 Correct 88 ms 149240 KB Output is correct
44 Correct 89 ms 149404 KB Output is correct
45 Correct 107 ms 150636 KB Output is correct
46 Correct 105 ms 150708 KB Output is correct
47 Correct 160 ms 154360 KB Output is correct
48 Correct 95 ms 149752 KB Output is correct
49 Correct 97 ms 149368 KB Output is correct
50 Correct 91 ms 149240 KB Output is correct
51 Correct 141 ms 155512 KB Output is correct
52 Correct 158 ms 155512 KB Output is correct
53 Correct 101 ms 153848 KB Output is correct
54 Correct 88 ms 153592 KB Output is correct
55 Correct 90 ms 153592 KB Output is correct
56 Correct 104 ms 154744 KB Output is correct
57 Correct 135 ms 153720 KB Output is correct
58 Correct 97 ms 154232 KB Output is correct
59 Correct 97 ms 154312 KB Output is correct
60 Correct 104 ms 154620 KB Output is correct
61 Correct 102 ms 154356 KB Output is correct
62 Correct 130 ms 156152 KB Output is correct
63 Correct 156 ms 177016 KB Output is correct
64 Correct 168 ms 185464 KB Output is correct
65 Correct 247 ms 183800 KB Output is correct
66 Correct 475 ms 177272 KB Output is correct
67 Correct 489 ms 177532 KB Output is correct