I - ドローン配送と高度制御 / Drone Delivery and Altitude Control Editorial by admin Editorial for printing
gpt-5.5-xhighOverview
In this problem, we are asked to find the minimum time to travel from base \(1\) at altitude \(S\) to base \(N\) at altitude \(T\). Before departure, we must choose an altitude range \([U,V]\) and perform all altitude adjustments and flight path traversals strictly within this range.
Since the number of possible altitudes is small (\(K \leq 10\)), we can iterate over all possible altitude ranges \([U,V]\) and solve a shortest path problem for each range, defining the state as \((\text{base} \times \text{altitude})\).
Analysis
First, the altitude range \([U,V]\) must be determined before departure.
Since the starting altitude is \(S\) and the destination altitude is \(T\), we must have:
\[ U \leq S \leq V \]
and
\[ U \leq T \leq V \]
Therefore, the ranges to search are:
\[ 0 \leq U \leq \min(S,T) \]
\[ \max(S,T) \leq V \leq K \]
Since \(K \leq 10\), there are at most \(O(K^2)\) such candidate pairs \([U,V]\).
Next, let us consider fixing a specific altitude range \([U,V]\).
In this case, representing the drone’s state solely by “which base it is currently at” is insufficient. This is because, even at the same base, the available flight paths and movement costs depend on the current altitude.
Thus, we represent the state as:
\[ (\text{base}, \text{altitude}) \]
For example, if \([U,V]=[2,4]\), base \(i\) has three states:
\[ (i,2), (i,3), (i,4) \]
On this state graph, we add the following transitions:
Increase altitude by \(1\) at base \(i\)
$\((i,x) \to (i,x+1)\)\( Cost is \)P_i$Decrease altitude by \(1\) at base \(i\)
$\((i,x) \to (i,x-1)\)\( Cost is \)Q_i$Use flight path \(j\)
If altitude \(x\) satisfies \(L_j \leq x \leq R_j\),
$\((A_j,x) \to (B_j,x)\)\( Cost is \)\( C_j + D_j \times |x-H_j| \)$
Traversing a flight path does not change the altitude, so the altitude at the destination remains \(x\).
Since all edge costs are non-negative, we can use Dijkstra’s algorithm on this graph to find the minimum travel time for a fixed \([U,V]\).
Finally, we add the time required to configure the altitude range:
\[ G \times (V-U) \]
We perform this process for all candidate ranges \([U,V]\) and take the minimum value as the answer.
Algorithm
Initialize the answer with a sufficiently large value
INF.Enumerate all valid altitude ranges \([U,V]\):
$\( 0 \leq U \leq \min(S,T) \)$
$\( \max(S,T) \leq V \leq K \)$
- For a fixed \([U,V]\), define the state as:
$\( (\text{base } v, \text{altitude } x) \)$
The number of states is:
$\( N \times (V-U+1) \)$
- Run Dijkstra’s algorithm with the starting point:
$\( (1,S) \)$
and the destination:
$\( (N,T) \)$
In Dijkstra’s algorithm, explore the following transitions from each state \((v,x)\):
- If \(x+1 \leq V\), increase the altitude.
- If \(x-1 \geq U\), decrease the altitude.
- For flight paths outgoing from base \(v\), traverse them if they are usable at altitude \(x\).
If the destination \((N,T)\) is reachable, add the range configuration cost:
$\( G \times (V-U) \)$
to the shortest distance, and update the answer.
- If the destination cannot be reached after trying all \([U,V]\), output
NA.
Complexity
- Time Complexity: \(O(K^3 (N+M) \log(NK))\)
- Space Complexity: \(O((N+M)K)\)
Since \(K \leq 10\), searching all altitude ranges and running Dijkstra’s algorithm for each range will run well within the time limit.
Implementation Notes
It is convenient to flatten the two-dimensional state into a 1D index for implementation.
For a fixed \([U,V]\), let the width be:
\[ W = V-U+1 \]
Then, the state \((v,x)\) can be uniquely indexed as:
\[ v \times W + (x-U) \]
Also, since the maximum cost can be quite large, use long long rather than int.
For the unreachable sentinel value INF, choosing a sufficiently large value such as:
const long long INF = (1LL << 62);
is safe.
Source Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (1LL << 62);
struct Edge {
int to, l, r, h;
ll c, d;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M, K;
ll G;
cin >> N >> M >> K >> G;
int S, T;
cin >> S >> T;
vector<ll> P(N), Q(N);
for (int i = 0; i < N; i++) {
cin >> P[i] >> Q[i];
}
vector<vector<Edge>> adj(N);
for (int j = 0; j < M; j++) {
int A, B, L, R, H;
ll C, D;
cin >> A >> B >> L >> R >> C >> H >> D;
--A;
--B;
adj[A].push_back({B, L, R, H, C, D});
}
ll ans = INF;
int minST = min(S, T);
int maxST = max(S, T);
for (int U = 0; U <= minST; U++) {
for (int V = maxST; V <= K; V++) {
int W = V - U + 1;
int SZ = N * W;
vector<ll> dist(SZ, INF);
auto id = [&](int v, int x) {
return v * W + (x - U);
};
int start = id(0, S);
int goal = id(N - 1, T);
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
dist[start] = 0;
pq.push({0, start});
while (!pq.empty()) {
auto [cur, s] = pq.top();
pq.pop();
if (cur != dist[s]) continue;
if (s == goal) break;
int v = s / W;
int idx = s % W;
int x = U + idx;
if (idx + 1 < W) {
int ns = s + 1;
ll nd = cur + P[v];
if (nd < dist[ns]) {
dist[ns] = nd;
pq.push({nd, ns});
}
}
if (idx > 0) {
int ns = s - 1;
ll nd = cur + Q[v];
if (nd < dist[ns]) {
dist[ns] = nd;
pq.push({nd, ns});
}
}
for (const auto& e : adj[v]) {
if (e.l <= x && x <= e.r) {
int ns = e.to * W + idx;
ll nd = cur + e.c + e.d * llabs((ll)x - e.h);
if (nd < dist[ns]) {
dist[ns] = nd;
pq.push({nd, ns});
}
}
}
}
if (dist[goal] < INF) {
ans = min(ans, dist[goal] + G * (V - U));
}
}
}
if (ans == INF) {
cout << "NA\n";
} else {
cout << ans << '\n';
}
return 0;
}
This editorial was generated by gpt-5.5-xhigh.
posted:
last update: