Submission #257438

# Submission time Handle Problem Language Result Execution time Memory
257438 2020-08-04T09:15:31 Z tinjyu Sky Walking (IOI19_walk) C++14
10 / 100
540 ms 535976 KB
#include "walk.h"
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct node{
	long long int dis,id;
}t[1000005];
long long int p[10000005],hp[10000005],dis[10000005],m,n,road[10000005],map[10000005][3],pointer[100005][50][2],num[100005],cont,st,cnt;
int connect(int a,int b,int len)
{
	//cout<<a<<" "<<p[a]<<" "<<hp[a]<<" "<<b<<" "<<p[b]<<" "<<hp[b]<<endl;
	cont++;
	map[cont][0]=b;
	map[cont][1]=road[a];
	map[cont][2]=len;
	road[a]=cont;
	cont++;
	map[cont][0]=a;
	map[cont][1]=road[b];
	map[cont][2]=len;
	road[b]=cont;
	return 0;
}
struct cmp{
	bool operator()(const node &a,const node &b)
	{
		return a.dis>b.dis;
	}
};
int dijk()
{
	for(int i=1;i<=cnt;i++)dis[i]=100000000000000;
	dis[st]=0;
	t[1].id=st;
	t[1].dis=0;
	long long int pp=1;
	while(pp>=1)
	{
		pop_heap(t+1,t+pp+1,cmp());
		long long int x=t[pp].id,len=t[pp].dis;
		pp--;
		if(len!=dis[x])
		{
			continue;
		}
		//cout<<x<<" "<<len<<" "<<p[x]<<endl;
		long long int g=road[x];
		while(g!=-1){
			long long int now=map[g][0];
			//cout<<now<<" "<<dis[now]<<" "<<p[now]<<" "<<hp[now]<<endl;
			if(len+map[g][2]<dis[now]){
				dis[now]=len+map[g][2];
				pp++;
				t[pp].id=now;
				t[pp].dis=dis[now];
				push_heap(t+1,t+pp+1,cmp());
			}
			g=map[g][1];
		}
		for(int i=1;i<=num[p[x]];i++)
		{
			long long int now=pointer[p[x]][i][0];
			if(now==x)continue;
			//cout<<now<<" "<<dis[now]<<" "<<p[now]<<" "<<hp[now]<<endl;
			if(len+abs(hp[x]-pointer[p[x]][i][1])<dis[now]){
				dis[now]=len+abs(hp[x]-pointer[p[x]][i][1]);
				pp++;
				t[pp].id=now;
				t[pp].dis=dis[now];
				push_heap(t+1,t+pp+1,cmp());
			}
			g=map[g][1];
		}
		//cout<<endl;

	}
	return 0;
}
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
	n=x.size();
	m=l.size();
	for(int i=0;i<=n*m;i++)road[i]=-1;
	st=0;
	for(int i=0;i<m;i++){
		cnt++;
		num[l[i]]++;
		p[cnt]=l[i];
		hp[cnt]=y[i];
		pointer[l[i]][num[l[i]]][0]=cnt;
		pointer[l[i]][num[l[i]]][1]=y[i];
		long long int pr=cnt,prex=x[l[i]];
		for(int j=l[i]+1;j<=r[i];j++){
			if(h[j]>=y[i])
			{
				cnt++;
				num[j]++;
				p[cnt]=j;
				hp[cnt]=y[i];
				pointer[j][num[j]][0]=cnt;
				pointer[j][num[j]][1]=y[i];
				connect(cnt,pr,x[j]-prex);
				pr=cnt;
				prex=x[j];
			}
		}
	}
	num[s]++;
	cnt++;
	p[cnt]=s;
	pointer[s][num[s]][0]=cnt;
	st=cnt;

	num[g]++;
	cnt++;
	p[cnt]=g;
	pointer[g][num[g]][0]=cnt;
	dijk();
	if(dis[cnt]>1000000000000)return -1;
	return dis[cnt];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Runtime error 540 ms 535976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 535288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 535288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Runtime error 540 ms 535976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Halted 0 ms 0 KB -