Submission #623188

# Submission time Handle Problem Language Result Execution time Memory
623188 2022-08-05T09:57:23 Z Dremix10 Sky Walking (IOI19_walk) C++17
10 / 100
4000 ms 1048576 KB
#include "walk.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#ifdef dremix
    #define p(x) cerr<<#x<<" = "<<x<<endl;
    #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
    #define pp(x) cerr<<#x<<" = "<<x.F<<"-"<<x.S<<endl;
    #define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v<<", ";cerr<<"}"<<endl;
    #define ppv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v.F<<"-"<<v.S<<", ";cerr<<"}"<<endl;
#else
    #define p(x) {}
    #define p2(x,y) {}
	#define pp(x) {}
    #define pv(x) {}
    #define ppv(x) {}
#endif
const int N = 3e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18+5;

struct ano{
	int x,who;
	ll d;

	bool operator<(const ano &x)const{
		return d > x.d;
	}
};

long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
	int n = x.size();
	int m = l.size();

	vector<vector<int> > a(n+m+1);

	int i,j;
	vector<vector<pi> > in(n),out(n);
	for(j=0;j<m;j++){
		in[l[j]].push_back({y[j],n+j});
		out[r[j]].push_back({y[j],n+j});
	}
	set<pi> st;
	for(i=0;i<n;i++){
		for(auto &x : in[i])st.insert(x);

		for(auto &x : st){
			if(x.F > h[i])break;
			j = x.S;
			a[i].push_back(j);
			a[j].push_back(i);
		}

		for(auto &x : out[i])st.erase(x);
	}
	//if(n > 50)assert(0);
	priority_queue<ano> q;
	
	vector<__gnu_pbds::gp_hash_table<int,ll> > d(n+m+1,__gnu_pbds::gp_hash_table<int,ll>());
	//vector<pl> dd(n+m,{INF,INF});
	
	q.push({s,n+m,0});

	int cnter=0;
	for(i=0;i<n+m;i++){
		for(auto &v : a[i]){
			d[i][v] = INF;
			cnter++;
		}
	}
	if(n>50)
		assert(cnter <= (m*10*2));
	d[s][n+m] = 0;
	y.push_back(0);
	//dd[s] = {0,h[s]};
	int cost;
	ll gg;
	ano temp;
	while(!q.empty()){
		temp = q.top();
		q.pop();
		gg = d[temp.x][temp.who];

		if(temp.d > gg)continue;
		
		

		if(temp.x >= n){
			for(auto &v : a[temp.x]){
				if(v == temp.who)continue;
				
				cost = abs(x[temp.who] - x[v]);

				
				if(d[v][temp.x] > gg + cost){
					d[v][temp.x] = gg + cost;
					d[temp.x][v] = gg + cost;
					q.push({v,temp.x,gg+cost});
				}
			}
		}
		else{
			/// not sky
			for(auto &v : a[temp.x]){
				if(v == temp.who)continue;
			
				cost = abs(y[temp.who-n] - y[v-n]);
				
				if(d[v][temp.x] > gg + cost){
					d[v][temp.x] = gg + cost;
					d[temp.x][v] = gg + cost;
					q.push({v,temp.x,gg+cost});
				}
			}
		}
	}
	ll ans = INF;
	for(auto v : a[g]){
		ans = min(ans,d[g][v]+y[v-n]);
	}
	if(ans == INF)ans = -1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3207 ms 143380 KB Output is correct
4 Correct 579 ms 160592 KB Output is correct
5 Correct 287 ms 137932 KB Output is correct
6 Correct 280 ms 127040 KB Output is correct
7 Correct 293 ms 138188 KB Output is correct
8 Execution timed out 4046 ms 187224 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 31532 KB Output is correct
2 Runtime error 1607 ms 1048576 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 31532 KB Output is correct
2 Runtime error 1607 ms 1048576 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 3207 ms 143380 KB Output is correct
21 Correct 579 ms 160592 KB Output is correct
22 Correct 287 ms 137932 KB Output is correct
23 Correct 280 ms 127040 KB Output is correct
24 Correct 293 ms 138188 KB Output is correct
25 Execution timed out 4046 ms 187224 KB Time limit exceeded
26 Halted 0 ms 0 KB -