답안 #603065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603065 2022-07-23T14:42:32 Z Koosha_mv Sky Walking (IOI19_walk) C++14
24 / 100
3201 ms 660712 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=2e6+99;
const ll inf=1e16;

int n,m,cnt,seg[N],vis[N];
ll dist[N];
vector<int> a,h,vec;
vector<int> V[N];
vector<pair<ll,ll>> g[N];
map<pair<int,int>,int> mark;

int get(int x,int y){
	if(mark.count(mp(x,y))) return mark[mp(x,y)];
	int p=lower_bound(all(a),x)-a.begin();
	V[p].pb(y);
	return mark[mp(x,y)]=++cnt;
}
void build(int id=1,int l=0,int r=n){
	if(l+1==r){
		seg[id]=h[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid,r);
	seg[id]=max(seg[id<<1],seg[id<<1|1]);
}
void get(int L,int R,int val,int id=1,int l=0,int r=n){
	if(r<=L || R<=l || seg[id]<val) return ;
	if(l+1==r){
		vec.pb(l);
		return ;
	}
	int mid=(l+r)>>1;
	get(L,R,val,id<<1,l,mid);
	get(L,R,val,id<<1|1,mid,r);
}

ll min_distance(vector<int> _a,vector<int> _h,vector<int> l,vector<int> r,vector<int> y,int S,int T) {
	a=_a,h=_h;
	n=a.size(),m=l.size();
	build();
	get(a[S],0);
	get(a[T],0);
	f(i,0,m){
		vec.clear();
		get(l[i],r[i]+1,y[i]);
		f(j,1,vec.size()){
			int u=get(a[vec[j-1]],y[i]),v=get(a[vec[j]],y[i]);
			g[u].pb({v,a[vec[j]]-a[vec[j-1]]});
			g[v].pb({u,a[vec[j]]-a[vec[j-1]]});
		}
		//dbgv(vec);
	}
	f(i,0,n){
		sort(all(V[i]));
		f(j,1,V[i].size()){
			int u=get(a[i],V[i][j-1]),v=get(a[i],V[i][j]);
			g[u].pb({v,V[i][j]-V[i][j-1]});
			g[v].pb({u,V[i][j]-V[i][j-1]});
		}
	}
	set<pair<ll,ll>> s;
	f(i,1,cnt+1) dist[i]=inf;
	dist[get(a[S],0)]=0;
	f(i,1,cnt+1) s.insert({dist[i],i});
	while(s.size()){
		int u=(*s.begin()).S;
		s.erase(*s.begin());
		//if(vis[u]) assert(0);
		vis[u]=1;
		for(auto [v,w] : g[u]){
			if(w<0) assert(0);
			if(dist[u]+w<dist[v]){
				if(vis[v]==1){
					if(dist[v]<dist[u]) assert(0);
				}
				s.erase({dist[v],v});
				dist[v]=dist[u]+w;
				s.insert({dist[v],v});
			}
		}
	}
	if(dist[get(a[T],0)]<inf){
		return dist[get(a[T],0)];
	}
	else{
		return -1;
	}
}
/*
5 3
0 6
4 6
5 6
6 6
9 6
3 4 1
1 3 3
0 2 6
0 4

0, 4, 5, 6, 9],
[6, 6, 6, 6, 6],
[3, 1, 0],
[4, 3, 2],
[1, 3, 6],
0, 4)
*/

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:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   70 |   f(j,1,vec.size()){
      |     ~~~~~~~~~~~~~~             
walk.cpp:70:3: note: in expansion of macro 'f'
   70 |   f(j,1,vec.size()){
      |   ^
walk.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   79 |   f(j,1,V[i].size()){
      |     ~~~~~~~~~~~~~~~            
walk.cpp:79:3: note: in expansion of macro 'f'
   79 |   f(j,1,V[i].size()){
      |   ^
walk.cpp:94:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   94 |   for(auto [v,w] : g[u]){
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94300 KB Output is correct
2 Correct 43 ms 94244 KB Output is correct
3 Correct 48 ms 94240 KB Output is correct
4 Correct 45 ms 94228 KB Output is correct
5 Correct 44 ms 94416 KB Output is correct
6 Correct 45 ms 94272 KB Output is correct
7 Correct 45 ms 94336 KB Output is correct
8 Correct 43 ms 94284 KB Output is correct
9 Correct 45 ms 94220 KB Output is correct
10 Correct 46 ms 94412 KB Output is correct
11 Correct 44 ms 94188 KB Output is correct
12 Correct 44 ms 94260 KB Output is correct
13 Correct 45 ms 94188 KB Output is correct
14 Correct 44 ms 94188 KB Output is correct
15 Correct 43 ms 94192 KB Output is correct
16 Correct 43 ms 94164 KB Output is correct
17 Correct 46 ms 94444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 94220 KB Output is correct
2 Correct 44 ms 94228 KB Output is correct
3 Correct 2383 ms 273760 KB Output is correct
4 Correct 1908 ms 272196 KB Output is correct
5 Correct 1263 ms 251384 KB Output is correct
6 Correct 1139 ms 230508 KB Output is correct
7 Correct 1284 ms 251300 KB Output is correct
8 Correct 3201 ms 329444 KB Output is correct
9 Correct 1420 ms 249696 KB Output is correct
10 Correct 2792 ms 355328 KB Output is correct
11 Correct 1038 ms 182648 KB Output is correct
12 Correct 555 ms 146176 KB Output is correct
13 Correct 2275 ms 318684 KB Output is correct
14 Correct 506 ms 144700 KB Output is correct
15 Correct 621 ms 146124 KB Output is correct
16 Correct 652 ms 149220 KB Output is correct
17 Correct 775 ms 146960 KB Output is correct
18 Correct 668 ms 146364 KB Output is correct
19 Correct 59 ms 96596 KB Output is correct
20 Correct 206 ms 118848 KB Output is correct
21 Correct 567 ms 145864 KB Output is correct
22 Correct 554 ms 145316 KB Output is correct
23 Correct 794 ms 158304 KB Output is correct
24 Correct 584 ms 147068 KB Output is correct
25 Correct 584 ms 146440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 110360 KB Output is correct
2 Runtime error 2193 ms 660712 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 110360 KB Output is correct
2 Runtime error 2193 ms 660712 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94300 KB Output is correct
2 Correct 43 ms 94244 KB Output is correct
3 Correct 48 ms 94240 KB Output is correct
4 Correct 45 ms 94228 KB Output is correct
5 Correct 44 ms 94416 KB Output is correct
6 Correct 45 ms 94272 KB Output is correct
7 Correct 45 ms 94336 KB Output is correct
8 Correct 43 ms 94284 KB Output is correct
9 Correct 45 ms 94220 KB Output is correct
10 Correct 46 ms 94412 KB Output is correct
11 Correct 44 ms 94188 KB Output is correct
12 Correct 44 ms 94260 KB Output is correct
13 Correct 45 ms 94188 KB Output is correct
14 Correct 44 ms 94188 KB Output is correct
15 Correct 43 ms 94192 KB Output is correct
16 Correct 43 ms 94164 KB Output is correct
17 Correct 46 ms 94444 KB Output is correct
18 Correct 50 ms 94220 KB Output is correct
19 Correct 44 ms 94228 KB Output is correct
20 Correct 2383 ms 273760 KB Output is correct
21 Correct 1908 ms 272196 KB Output is correct
22 Correct 1263 ms 251384 KB Output is correct
23 Correct 1139 ms 230508 KB Output is correct
24 Correct 1284 ms 251300 KB Output is correct
25 Correct 3201 ms 329444 KB Output is correct
26 Correct 1420 ms 249696 KB Output is correct
27 Correct 2792 ms 355328 KB Output is correct
28 Correct 1038 ms 182648 KB Output is correct
29 Correct 555 ms 146176 KB Output is correct
30 Correct 2275 ms 318684 KB Output is correct
31 Correct 506 ms 144700 KB Output is correct
32 Correct 621 ms 146124 KB Output is correct
33 Correct 652 ms 149220 KB Output is correct
34 Correct 775 ms 146960 KB Output is correct
35 Correct 668 ms 146364 KB Output is correct
36 Correct 59 ms 96596 KB Output is correct
37 Correct 206 ms 118848 KB Output is correct
38 Correct 567 ms 145864 KB Output is correct
39 Correct 554 ms 145316 KB Output is correct
40 Correct 794 ms 158304 KB Output is correct
41 Correct 584 ms 147068 KB Output is correct
42 Correct 584 ms 146440 KB Output is correct
43 Correct 202 ms 110360 KB Output is correct
44 Runtime error 2193 ms 660712 KB Execution killed with signal 6
45 Halted 0 ms 0 KB -