답안 #1046403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046403 2024-08-06T13:53:56 Z idas Sky Walking (IOI19_walk) C++17
33 / 100
123 ms 15172 KB
#include "walk.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

const ll LINF=1e18;
const int N=1e5+10;
int n, m;
vector<pii> ins;
ll d[N];

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

	FOR(i, 0, m) {
		l[i]=x[l[i]];
		r[i]=x[r[i]];
		d[i]=LINF;
	}

	FOR(i, 0, m) {
		ins.pb({l[i],i});
		ins.pb({r[i],i});
		if(l[i]==x[0]) d[i]=min(d[i], 1LL*y[i]+r[i]-l[i]);
	}

	sort(ins.begin(), ins.end());

	set<pii> st;
	ll ans=LINF;
	FOR(i, 0, 2*m) {
		vector<pii> now;
		while(i+1<2*m && ins[i+1].f==ins[i].f) {
			int pos=ins[i].f, in=ins[i].s;
			if(pos==l[in]) st.insert({y[in],in});
			else now.pb(ins[i]);
			i++;
		}
		int poss=ins[i].f, inn=ins[i].s;
		if(poss==l[inn]) st.insert({y[inn],inn});
		else now.pb(ins[i]);

		for(auto[pos, in] : now) {
			assert(pos!=l[in]);
			st.erase({y[in],in});
		}

		for(auto[pos, in] : now) {
			// cout << pos << ": ";
			assert(pos!=l[in]);

			auto up=st.lower_bound({y[in],0});

			// cout << pos << ": ";

			if(up!=st.end()) {
				ll new_up=d[in] + abs(up->f - y[in]) + r[up->s]-r[in];
				d[up->s]=min(d[up->s], new_up);
				// cout << "u: " << up->f << " ";
			}

			auto down=st.upper_bound({y[in],0});
			if(down!=st.begin()) {
				--down;
				ll new_down=d[in] + abs(down->f - y[in]) + r[down->s]-r[in];
				d[down->s]=min(d[down->s], new_down);
				// cout << "d: " << up->f << " ";
			}

			if(r[in]==x[n-1]) {
				ans=min(ans, d[in]+y[in]);
			}
		}
	}

	// FOR(i, 0, m) {
	// 	cout << i << ": " << d[i] << endl;
	// }

	return (ans==LINF?-1:ans);
}
/*
3 5
0 3
3 3
5 2
0 1 2
0 1 1
1 2 1
1 2 2
0 1 3
0 2
ans: 7

1:
6 6
0 4
1 4
2 4
4 4
7 4
9 4
0 2 3
0 1 1
1 2 2
1 4 0
2 3 1
2 5 4
0 5
ans: 17

2:
5 4
0 4
2 4
4 4
5 4
6 4
0 1 2
1 2 1
1 3 3
1 4 4
0 4
ans: 14

3:
7 5
0 4
2 4
3 4
4 4
6 4
8 4
9 4
0 1 1
1 3 2
2 4 0
3 4 1
3 6 3
0 6

in1: 28
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3284 KB Output is correct
2 Correct 68 ms 5584 KB Output is correct
3 Correct 72 ms 5840 KB Output is correct
4 Correct 81 ms 7120 KB Output is correct
5 Correct 103 ms 11196 KB Output is correct
6 Correct 111 ms 9156 KB Output is correct
7 Correct 49 ms 4552 KB Output is correct
8 Correct 53 ms 7204 KB Output is correct
9 Correct 99 ms 9820 KB Output is correct
10 Correct 57 ms 9404 KB Output is correct
11 Correct 5 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3284 KB Output is correct
2 Correct 68 ms 5584 KB Output is correct
3 Correct 72 ms 5840 KB Output is correct
4 Correct 81 ms 7120 KB Output is correct
5 Correct 103 ms 11196 KB Output is correct
6 Correct 111 ms 9156 KB Output is correct
7 Correct 49 ms 4552 KB Output is correct
8 Correct 53 ms 7204 KB Output is correct
9 Correct 99 ms 9820 KB Output is correct
10 Correct 57 ms 9404 KB Output is correct
11 Correct 5 ms 1112 KB Output is correct
12 Correct 75 ms 7888 KB Output is correct
13 Correct 83 ms 11200 KB Output is correct
14 Correct 123 ms 15172 KB Output is correct
15 Correct 65 ms 11200 KB Output is correct
16 Correct 67 ms 11412 KB Output is correct
17 Correct 66 ms 11460 KB Output is correct
18 Correct 69 ms 11196 KB Output is correct
19 Correct 70 ms 11520 KB Output is correct
20 Correct 43 ms 7632 KB Output is correct
21 Correct 13 ms 3912 KB Output is correct
22 Correct 69 ms 10440 KB Output is correct
23 Correct 60 ms 10692 KB Output is correct
24 Correct 53 ms 10972 KB Output is correct
25 Correct 53 ms 10448 KB Output is correct
26 Correct 54 ms 12108 KB Output is correct
27 Correct 103 ms 14524 KB Output is correct
28 Correct 69 ms 11556 KB Output is correct
29 Correct 94 ms 13248 KB Output is correct
30 Correct 41 ms 7624 KB Output is correct
31 Correct 89 ms 13756 KB Output is correct
32 Correct 55 ms 10944 KB Output is correct
33 Correct 49 ms 11200 KB Output is correct
34 Correct 58 ms 11436 KB Output is correct
35 Correct 55 ms 10180 KB Output is correct
36 Correct 44 ms 9936 KB Output is correct
37 Correct 42 ms 9668 KB Output is correct
38 Correct 47 ms 10436 KB Output is correct
39 Correct 79 ms 12732 KB Output is correct
40 Correct 44 ms 10180 KB Output is correct
41 Correct 43 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -