求调(玄关,but 非此号)
  • 板块灌水区
  • 楼主pengbonan
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/6 20:44
  • 上次更新2025/1/7 17:18:48
查看原帖
求调(玄关,but 非此号)
1005693
pengbonan楼主2025/1/6 20:44

60pts, WA on 47, 59
P10726 [GESP202406 八级] 空间跳跃

#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
constexpr int maxn = 1e5, inf = INT_MAX;
struct LL {
	int l, r, h, id;
} A[maxn];
int ans = inf;
int s, t, ns, nt;
unordered_map <int, bool> mp[maxn];
void dfs (int loc, int dep, int sum) {
	if (dep == nt) {
		ans = min(ans, sum);
		return;
	}
	if (mp[dep][loc]) return;
	pair <bool, bool> vis;
	vis.first = vis.second = 0;
	for (int nxt = dep + 1; nxt <= nt; nxt ++) {
		if (A[nxt].l <= A[dep].l && A[nxt].r >= A[dep].l && !vis.first) {
			dfs(A[dep].l, nxt, sum + loc - A[dep].l + A[dep].h - A[nxt].h);
			vis.first = 1;
		}
		if (A[nxt].l <= A[dep].r && A[nxt].r >= A[dep].r && !vis.second) {
			dfs(A[dep].r, nxt, sum + A[dep].r - loc + A[dep].h - A[nxt].h);
			vis.second = 1;
		}
	}
	mp[dep][loc] = 1;
}
int main () {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	cin >> s >> t;
	for (int i = 1; i <= n; i ++)
		cin >> A[i].l >> A[i].r >> A[i].h, A[i].id = i;
	sort(A + 1, A + n + 1, [](LL a, LL b) {
		return a.h >= b.h;
	} );
	for (int i = 1; i <= n; i ++) {
		if (A[i].id == s) ns = i;
		if (A[i].id == t) nt = i;
		if (ns != 0 && nt != 0) break;
	}
	if (ns > nt) cout << -1;
	else {
		dfs(A[ns].l, ns, 0);
		if (ans == inf) cout << -1;
		else cout << ans;
	}
	return 0;
}
2025/1/6 20:44
加载中...