Submission #1046345

# Submission time Handle Problem Language Result Execution time Memory
1046345 2024-08-06T13:17:52 Z idas Sky Walking (IOI19_walk) C++17
0 / 100
106 ms 15264 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) {
			now.pb(ins[i]);
			i++;
		}
		now.pb(ins[i]);

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

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

			if(pos==l[in]) continue;
			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;
}
/*
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

7

in1: 28
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3280 KB Output is correct
2 Correct 72 ms 5600 KB Output is correct
3 Correct 72 ms 7884 KB Output is correct
4 Correct 86 ms 11312 KB Output is correct
5 Correct 106 ms 15264 KB Output is correct
6 Correct 99 ms 13252 KB Output is correct
7 Correct 39 ms 7636 KB Output is correct
8 Correct 47 ms 11204 KB Output is correct
9 Correct 91 ms 13996 KB Output is correct
10 Correct 66 ms 12876 KB Output is correct
11 Incorrect 6 ms 1880 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3280 KB Output is correct
2 Correct 72 ms 5600 KB Output is correct
3 Correct 72 ms 7884 KB Output is correct
4 Correct 86 ms 11312 KB Output is correct
5 Correct 106 ms 15264 KB Output is correct
6 Correct 99 ms 13252 KB Output is correct
7 Correct 39 ms 7636 KB Output is correct
8 Correct 47 ms 11204 KB Output is correct
9 Correct 91 ms 13996 KB Output is correct
10 Correct 66 ms 12876 KB Output is correct
11 Incorrect 6 ms 1880 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -