Submission #606519

# Submission time Handle Problem Language Result Execution time Memory
606519 2022-07-26T07:00:06 Z rrrr10000 Sky Walking (IOI19_walk) C++14
33 / 100
940 ms 141724 KB
#include "walk.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define SPQ(a) priority_queue<a,vector<a>,greater<a>>
#define fi first
#define se second
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void outvp(T v){rep(i,v.size()){cout<<'('<<v[i].fi<<','<<v[i].se<<')';}cout<<endl;}
const ll inf=1001001001001001001;
ll dijkstra(ll n,vector<PP> edge,ll from,ll to){
	vvp g(n);
	for(auto x:edge){
		ll a,b,c;tie(a,b,c)=x;
		g[a].pb(b,c);g[b].pb(a,c);
	}
	SPQ(P) pq;pq.emplace(0,from);
	vi dis(n,inf);dis[from]=0;
	while(!pq.empty()){
		auto t=pq.top();pq.pop();
		if(dis[t.se]!=t.fi)continue;
		for(auto x:g[t.se])if(chmin(dis[x.fi],t.fi+x.se))pq.emplace(dis[x.fi],x.fi);
	}
	if(dis[to]==inf)return -1;
	return dis[to];
}
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 from, int to) {
	ll n=x.size(),m=l.size();
	set<P> S;
	vvi L(n),R(n);
	rep(i,m)L[l[i]].pb(i);
	rep(i,m)R[r[i]].pb(i);
	ll cnt=0,F,T;
	vvp yoko(m);
	vector<PP> edge;
	rep(i,n){
		vp sp;
		for(ll t:L[i])S.insert(P(y[t],t));
		for(ll t:L[i]){
			sp.pb(y[t],t);
			auto itr=S.lower_bound(P(y[t],t));
			if(itr!=S.begin()){
				itr--;sp.pb(*itr);
			}
		}
		for(ll t:R[i]){
			sp.pb(y[t],t);
			auto itr=S.lower_bound(P(y[t],t));
			if(itr!=S.begin()){
				itr--;sp.pb(*itr);
			}
		}
		if(S.size())sp.pb(*S.begin());
		sp.pb(0,-1);
		for(ll t:R[i])S.erase(P(y[t],t));
		dupli(sp);
		while(sp.size()&&sp.back().fi>h[i])sp.pop_back();
		rep(j,sp.size()-1){
			edge.pb(cnt+j,cnt+j+1,sp[j+1].fi-sp[j].fi);
		}
		REP(j,1,sp.size())yoko[sp[j].se].pb(i,cnt+j);
		if(from==i)F=cnt;
		if(to==i)T=cnt;
		cnt+=sp.size();
	}
	rep(i,m)rep(j,yoko[i].size()-1)edge.pb(yoko[i][j].se,yoko[i][j+1].se,x[yoko[i][j+1].fi]-x[yoko[i][j].fi]);
	return dijkstra(cnt,edge,F,T);
}

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:79:17: warning: 'F' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |  return dijkstra(cnt,edge,F,T);
      |         ~~~~~~~~^~~~~~~~~~~~~~
walk.cpp:79:17: warning: 'T' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 28564 KB Output is correct
2 Correct 541 ms 98108 KB Output is correct
3 Correct 554 ms 103716 KB Output is correct
4 Correct 729 ms 138924 KB Output is correct
5 Correct 885 ms 141724 KB Output is correct
6 Correct 923 ms 134520 KB Output is correct
7 Correct 408 ms 89240 KB Output is correct
8 Correct 252 ms 68440 KB Output is correct
9 Correct 841 ms 128008 KB Output is correct
10 Correct 335 ms 79108 KB Output is correct
11 Correct 15 ms 7152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 28564 KB Output is correct
2 Correct 541 ms 98108 KB Output is correct
3 Correct 554 ms 103716 KB Output is correct
4 Correct 729 ms 138924 KB Output is correct
5 Correct 885 ms 141724 KB Output is correct
6 Correct 923 ms 134520 KB Output is correct
7 Correct 408 ms 89240 KB Output is correct
8 Correct 252 ms 68440 KB Output is correct
9 Correct 841 ms 128008 KB Output is correct
10 Correct 335 ms 79108 KB Output is correct
11 Correct 15 ms 7152 KB Output is correct
12 Correct 548 ms 103416 KB Output is correct
13 Correct 545 ms 137228 KB Output is correct
14 Correct 834 ms 141256 KB Output is correct
15 Correct 558 ms 109208 KB Output is correct
16 Correct 559 ms 122248 KB Output is correct
17 Correct 651 ms 138608 KB Output is correct
18 Correct 586 ms 109212 KB Output is correct
19 Correct 624 ms 121636 KB Output is correct
20 Correct 412 ms 86976 KB Output is correct
21 Correct 88 ms 40704 KB Output is correct
22 Correct 486 ms 116508 KB Output is correct
23 Correct 444 ms 110568 KB Output is correct
24 Correct 341 ms 80964 KB Output is correct
25 Correct 365 ms 100916 KB Output is correct
26 Correct 282 ms 62964 KB Output is correct
27 Correct 940 ms 140704 KB Output is correct
28 Correct 509 ms 136508 KB Output is correct
29 Correct 817 ms 133176 KB Output is correct
30 Correct 366 ms 88888 KB Output is correct
31 Correct 767 ms 126580 KB Output is correct
32 Correct 324 ms 71016 KB Output is correct
33 Correct 311 ms 72828 KB Output is correct
34 Correct 377 ms 78784 KB Output is correct
35 Correct 382 ms 83548 KB Output is correct
36 Correct 341 ms 71940 KB Output is correct
37 Correct 254 ms 63044 KB Output is correct
38 Correct 319 ms 67544 KB Output is correct
39 Correct 449 ms 80408 KB Output is correct
40 Correct 257 ms 67004 KB Output is correct
41 Correct 259 ms 65636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -