Untitled
unknown
c_cpp
2 years ago
709 B
13
Indexable
#include <iostream>
#include <vector>
using namespace std;
vector<int> shortestPath(int N, int X, int Y) {
vector<int> result(N, 0);
for (int k = 1; k <= N; k++) {
if (k < abs(Y - X) + 1) {
result[k - 1] = k - 1;
} else if (k == abs(Y - X) + 1) {
result[k - 1] = k - 1 + min(X, Y) - 1 + N - max(X, Y);
} else {
result[k - 1] = result[2 * abs(Y - X) + 1 - k - 1];
}
}
return result;
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<int> result = shortestPath(N, X, Y);
for (int k = 0; k < N; k++) {
cout << result[k] << " ";
}
return 0;
}
Editor is loading...