Submission #542605

# Submission time Handle Problem Language Result Execution time Memory
542605 2022-03-27T05:33:14 Z jamezzz Sky Walking (IOI19_walk) C++17
0 / 100
1277 ms 165180 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 1000005

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});
			}
		}
	}
	return dist[getid(x[g],0)];
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Incorrect 24 ms 47188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47180 KB Output is correct
2 Correct 24 ms 47248 KB Output is correct
3 Correct 1277 ms 156144 KB Output is correct
4 Correct 1158 ms 165180 KB Output is correct
5 Correct 821 ms 150784 KB Output is correct
6 Correct 736 ms 139000 KB Output is correct
7 Incorrect 812 ms 150712 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 54548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 54548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Incorrect 24 ms 47188 KB Output isn't correct
4 Halted 0 ms 0 KB -