Submission #111019

# Submission time Handle Problem Language Result Execution time Memory
111019 2019-05-13T14:42:08 Z aleksam Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
141 ms 34296 KB
//Jakarta skysrcapers
#include <bits/stdc++.h>
#define INF MOD
#define MOD 100000007
#define MAX_N 30005
#define MAX_M 30005

using namespace std;

int N, M;
int source, dest;
struct edge{
	int d, w;
};
vector<int> soli[MAX_N];
vector<edge> adj[MAX_N];
int dist[MAX_N];
bool mark[MAX_N];

void dijkstra(int s){
	memset(dist, INF, sizeof(dist));
	memset(mark, 0, sizeof(mark));
	
	dist[s]=0;
	priority_queue<pair<int, int> > pq;
	pq.emplace(0, s);
	while(!pq.empty()){
		auto cur=pq.top();
		pq.pop();
		int v=cur.second;
		if(mark[v])continue;
		//printf("v=%d\n", v);
		mark[v]=1;
		//dist[v]=-1*cur.first;
		int d=adj[v].size();
		for(int i=0; i<d; ++i){
			int u=adj[v][i].d;
			if(!mark[u] && dist[u]>dist[v]+adj[v][i].w){
				dist[u]=dist[v]+adj[v][i].w;
				pq.emplace(-1*(dist[v]+adj[v][i].w), u);
			}
		}
	}
}
bool cmp(int i, int j){return i>j;}
int main(){
	//ios::sync_with_stdio(false);
	cin>>N>>M;
	assert(N<=27000);
	int b;
	cin>>source>>b;
	soli[source].push_back(b);
	cin>>dest>>b;
	soli[dest].push_back(b);
	for(int i=2; i<M; ++i){
		int p;
		cin>>b>>p;
		soli[b].push_back(p);
	}
	for(int i=0; i<N; ++i){
		int d=soli[i].size();
		memset(mark, 0, sizeof(mark));
		sort(soli[i].begin(), soli[i].end(), cmp);
		for(int j=0; j<d; ++j){
			int p=soli[i][j];
			int sk=i-p;
			while(sk>=0){
				if(!mark[sk]){
					mark[sk]=1;
					edge e;
					e.d=sk;
					e.w=(i-sk)/p;
					adj[i].push_back(e);
				}
				sk-=p;
			}
			sk=i+p;
			while(sk<N){
				if(!mark[sk]){
					mark[sk]=1;
					edge e;
					e.d=sk;
					e.w=(sk-i)/p;
					adj[i].push_back(e);
				}
				sk+=p;
			}
		}
	}
	/*for(int i=0; i<N; ++i){
		int d=adj[i].size();
		printf("adj[%d]:", i);
		for(int j=0; j<d; ++j){
			printf("%d ", adj[i][j].d);
		}
		printf("\n");
	}*/
	dijkstra(source);
	if(dist[dest]>100000000)cout<<"-1"<<endl;
	else 
	cout<<dist[dest];
	return 0;
}

/*
5 3
0 2
1 1
4 1
*/
/*
4 4 
0 1 1
1 2 2 
2 3 1 
1 3 4
0 3

5 6 
0 1 1
1 2 2 
2 3 1 
1 3 4
0 4 2
4 3 1
0 3


3
3 2
1 2 5
2 3 7
1 3
3 3
1 2 4
1 3 7
2 3 1
1 3
3 1
1 2 4
1 3
*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 3 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 4 ms 1792 KB Output is correct
13 Correct 8 ms 1920 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 7 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 0 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 6 ms 1920 KB Output is correct
12 Correct 5 ms 1920 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 5 ms 2176 KB Output is correct
18 Correct 5 ms 1920 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 86 ms 34040 KB Output is correct
21 Correct 5 ms 1920 KB Output is correct
22 Correct 5 ms 1920 KB Output is correct
23 Correct 5 ms 2020 KB Output is correct
24 Correct 6 ms 2048 KB Output is correct
25 Correct 9 ms 2048 KB Output is correct
26 Correct 9 ms 2036 KB Output is correct
27 Correct 12 ms 2048 KB Output is correct
28 Correct 6 ms 2176 KB Output is correct
29 Correct 7 ms 2304 KB Output is correct
30 Correct 8 ms 2176 KB Output is correct
31 Correct 7 ms 2304 KB Output is correct
32 Correct 5 ms 2176 KB Output is correct
33 Correct 10 ms 2560 KB Output is correct
34 Correct 7 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 3 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 3 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 5 ms 1920 KB Output is correct
13 Correct 5 ms 2048 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 5 ms 1920 KB Output is correct
17 Correct 6 ms 2176 KB Output is correct
18 Correct 5 ms 1920 KB Output is correct
19 Correct 9 ms 1920 KB Output is correct
20 Correct 98 ms 34040 KB Output is correct
21 Correct 4 ms 1920 KB Output is correct
22 Correct 7 ms 1920 KB Output is correct
23 Correct 8 ms 2048 KB Output is correct
24 Correct 8 ms 2048 KB Output is correct
25 Correct 7 ms 2048 KB Output is correct
26 Correct 10 ms 2048 KB Output is correct
27 Correct 8 ms 1920 KB Output is correct
28 Correct 7 ms 2176 KB Output is correct
29 Correct 7 ms 2304 KB Output is correct
30 Correct 6 ms 2048 KB Output is correct
31 Correct 7 ms 2304 KB Output is correct
32 Correct 7 ms 2176 KB Output is correct
33 Correct 9 ms 2560 KB Output is correct
34 Correct 10 ms 2560 KB Output is correct
35 Correct 28 ms 3584 KB Output is correct
36 Correct 9 ms 2176 KB Output is correct
37 Correct 29 ms 4992 KB Output is correct
38 Correct 27 ms 4480 KB Output is correct
39 Correct 32 ms 4728 KB Output is correct
40 Correct 29 ms 4600 KB Output is correct
41 Correct 38 ms 4472 KB Output is correct
42 Correct 66 ms 2140 KB Output is correct
43 Correct 64 ms 2168 KB Output is correct
44 Correct 141 ms 34168 KB Output is correct
45 Correct 27 ms 4352 KB Output is correct
46 Correct 26 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 3 ms 1920 KB Output is correct
4 Correct 3 ms 1920 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 1920 KB Output is correct
8 Correct 3 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 5 ms 1920 KB Output is correct
13 Correct 6 ms 2048 KB Output is correct
14 Correct 5 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 5 ms 2176 KB Output is correct
18 Correct 5 ms 1920 KB Output is correct
19 Correct 5 ms 1920 KB Output is correct
20 Correct 79 ms 34012 KB Output is correct
21 Correct 5 ms 1920 KB Output is correct
22 Correct 6 ms 1920 KB Output is correct
23 Correct 5 ms 1920 KB Output is correct
24 Correct 7 ms 2048 KB Output is correct
25 Correct 6 ms 2028 KB Output is correct
26 Correct 8 ms 2048 KB Output is correct
27 Correct 8 ms 1920 KB Output is correct
28 Correct 7 ms 2176 KB Output is correct
29 Correct 6 ms 2304 KB Output is correct
30 Correct 5 ms 2048 KB Output is correct
31 Correct 6 ms 2304 KB Output is correct
32 Correct 6 ms 2176 KB Output is correct
33 Correct 7 ms 2432 KB Output is correct
34 Correct 8 ms 2688 KB Output is correct
35 Correct 28 ms 3576 KB Output is correct
36 Correct 9 ms 2176 KB Output is correct
37 Correct 23 ms 5120 KB Output is correct
38 Correct 31 ms 4472 KB Output is correct
39 Correct 42 ms 4736 KB Output is correct
40 Correct 32 ms 4608 KB Output is correct
41 Correct 34 ms 4480 KB Output is correct
42 Correct 87 ms 2168 KB Output is correct
43 Correct 61 ms 2168 KB Output is correct
44 Correct 136 ms 34296 KB Output is correct
45 Correct 25 ms 4344 KB Output is correct
46 Correct 24 ms 4472 KB Output is correct
47 Correct 86 ms 13440 KB Output is correct
48 Correct 43 ms 4824 KB Output is correct
49 Correct 38 ms 3832 KB Output is correct
50 Runtime error 6 ms 3328 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Halted 0 ms 0 KB -