Submission #542617

# Submission time Handle Problem Language Result Execution time Memory
542617 2022-03-27T07:23:05 Z jamezzz Sky Walking (IOI19_walk) C++17
0 / 100
1651 ms 381072 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll,int> li;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 100005

struct tower{
	int x,h,i;
};

struct bridge{
	int l,r,h,i;
};

int n,m,cnt,nx[maxn],pv[maxn];
vector<tower> towers;
vector<bridge> bridges;
map<ll,int> id;
vector<int> stuff[maxn];
vector<ii> AL[1000005];
ll dist[1000005];
priority_queue<li,vector<li>,greater<li>> pq;

int getid(int x,int y){
	ll h=(ll)x*1e9+y;
	if(!id.count(h))id[h]=cnt++;
	return id[h];
}

ll min_distance(vi x,vi h,vi l,vi r,vi y,int s,int g){
	n=sz(x);m=sz(l);
	for(int i=0;i<n;++i){
		towers.pb({x[i],h[i],i+1});
	}
	for(int i=0;i<m;++i){
		bridges.pb({l[i]+1,r[i]+1,y[i],i+1});
	}
	sort(all(towers),[](tower &a,tower &b){return a.h<b.h;});
	sort(all(bridges),[](bridge &a,bridge &b){return a.h<b.h;});
	for(int i=1;i<=n;++i)pv[i]=i-1,nx[i]=i+1;
	int ptr=0;
	for(int i=0;i<m;++i){
		while(ptr!=n&&towers[ptr].h<bridges[i].h){
			int j=towers[ptr].i;
			nx[pv[j]]=nx[j];
			pv[nx[j]]=pv[j];
			++ptr;
		}
		int old=-1,cur=bridges[i].l;
		while(cur<=bridges[i].r){
			stuff[cur].pb(bridges[i].h);
			if(old!=-1){
				int a=getid(x[old-1],bridges[i].h);
				int b=getid(x[cur-1],bridges[i].h);
				int d=x[cur-1]-x[old-1];
				AL[a].pb({b,d});
				AL[b].pb({a,d});
			}
			old=cur;
			cur=nx[cur];
		}
	}
	for(int i=1;i<=n;++i){
		stuff[i].pb(0);
		disc(stuff[i]);
		for(int j=1;j<sz(stuff[i]);++j){
			int a=getid(x[i-1],stuff[i][j-1]);
			int b=getid(x[i-1],stuff[i][j]);
			int d=stuff[i][j]-stuff[i][j-1];
			AL[a].pb({b,d});
			AL[b].pb({a,d});
		}
	}
	for(int i=0;i<=cnt;++i)dist[i]=LINF;
	int src=getid(x[s],0);
	dist[src]=0;pq.push({0,src});
	while(!pq.empty()){
		ll d;int u;
		tie(d,u)=pq.top();
		pq.pop();
		if(d>dist[u])continue;
		for(auto[v,w]:AL[u]){
			if(dist[v]>dist[u]+w){
				dist[v]=dist[u]+w;
				pq.push({dist[v],v});
			}
		}
	}
	ll ans=dist[getid(x[g],0)];
	return (ans!=LINF)?ans:-1;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 26068 KB Output is correct
2 Correct 13 ms 26068 KB Output is correct
3 Incorrect 14 ms 26068 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 26068 KB Output is correct
2 Correct 13 ms 26068 KB Output is correct
3 Correct 1306 ms 135512 KB Output is correct
4 Correct 1153 ms 144784 KB Output is correct
5 Correct 814 ms 130184 KB Output is correct
6 Correct 734 ms 118592 KB Output is correct
7 Correct 806 ms 130440 KB Output is correct
8 Correct 1651 ms 167684 KB Output is correct
9 Correct 932 ms 130416 KB Output is correct
10 Runtime error 1429 ms 381072 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 33808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 33808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 26068 KB Output is correct
2 Correct 13 ms 26068 KB Output is correct
3 Incorrect 14 ms 26068 KB Output isn't correct
4 Halted 0 ms 0 KB -