Submission #542624

# Submission time Handle Problem Language Result Execution time Memory
542624 2022-03-27T08:18:38 Z jamezzz Sky Walking (IOI19_walk) C++17
0 / 100
1762 ms 380052 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

#define maxn 100005

int n,m,par[maxn];
vector<int> b[maxn];
map<ll,int> id;
int cnt;
ll dist[10*maxn];
vii AL[10*maxn];
priority_queue<li,vector<li>,greater<li>> pq;

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

int fp(int i){
	return (par[i]==i)?i:par[i]=fp(par[i]);
}

ll min_distance(vi x,vi h,vi l,vi r,vi y,int s,int g){
	n=sz(x);m=sz(l);
	vector<ii> v1,v2;
	for(int i=0;i<n;++i)v1.pb({h[i],i});
	for(int i=0;i<m;++i)v2.pb({y[i],i});
	sort(all(v1));sort(all(v2));
	
	for(int i=0;i<=n;++i)par[i]=i;
	int ptr=0;
	for(int i=0;i<m;++i){
		while(ptr!=n&&v1[ptr].fi<v2[i].fi){
			int j=v1[ptr].se;
			if(j!=0)par[j-1]=j;
			++ptr;
		}
		int j=v2[i].se;
		int pv=-1,cur=l[j];
		while(cur<=r[j]){
			b[cur].pb(v2[i].fi);
			if(pv!=-1){
				int u=getid(x[pv],v2[i].fi);
				int v=getid(x[cur],v2[i].fi);
				int w=x[cur]-x[pv];
				AL[u].pb({v,w});
				AL[v].pb({u,w});
			}
			pv=cur;
			cur=fp(cur)+1;
		}
	}
	for(int i=0;i<n;++i){
		b[i].pb(0);
		disc(b[i]);
		for(int j=1;j<sz(b[i]);++j){
			int u=getid(x[i],b[i][j-1]);
			int v=getid(x[i],b[i][j]);
			int w=b[i][j]-b[i][j-1];
			AL[u].pb({v,w});
			AL[v].pb({u,w});
		}
	}
	
	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()){
		auto[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)?-1:ans;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26068 KB Output is correct
2 Correct 14 ms 26040 KB Output is correct
3 Incorrect 16 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 14 ms 26068 KB Output is correct
3 Correct 1346 ms 133852 KB Output is correct
4 Correct 1208 ms 142292 KB Output is correct
5 Correct 846 ms 127884 KB Output is correct
6 Correct 753 ms 116204 KB Output is correct
7 Correct 865 ms 128064 KB Output is correct
8 Correct 1762 ms 164532 KB Output is correct
9 Correct 1022 ms 125512 KB Output is correct
10 Runtime error 1446 ms 380052 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 32804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 32804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26068 KB Output is correct
2 Correct 14 ms 26040 KB Output is correct
3 Incorrect 16 ms 26068 KB Output isn't correct
4 Halted 0 ms 0 KB -