Untitled

mail@pastecode.io avatarunknown
c_cpp
a month ago
1.1 kB
3
Indexable
Never
#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++) {
        // Calculate the number of pairs for each k
        if (k == 1) {
            result[k - 1] = min(X, Y) - 1 + N - max(X, Y);
        } else {
            result[k - 1] = 0; // Initialize to 0, since we don't know yet
            if (k <= abs(Y - X) + 1) {
                result[k - 1]++; // The direct path from X to Y
            }
            if (k <= abs(N - max(X, Y) + min(X, Y)) + 1) {
                result[k - 1] += min(X, Y) - 1; // Paths from X to N and Y to N
            }
            if (k <= abs(max(X, Y) - 1) + min(X, Y)) {
                result[k - 1] += N - max(X, Y); // Paths from 1 to X and 1 to Y
            }
        }
    }
    
    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;
}