Submission

Status:

[PxSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: theem1502

Problemset: Path Finding

Language: c

Time: 0.003 second

Submitted On: 2025-09-25 22:45:07

#include <stdio.h>
#include <stdlib.h>

int main() {
    int row, collumn;
    scanf("%d", &row);
    collumn = row;
    int num;
    scanf("%d", &num);
    int *xcoordinates = malloc(num * sizeof(int));
    int  *ycoordinates = malloc(num * sizeof(int));

    for (int i = 0; i < num; i++) {
        scanf("%d %d", &xcoordinates[i], &ycoordinates[i]);
    }
    char **thearray = malloc(row * sizeof(char*));
    for (int  i = 0; i < row; i++) {
        thearray[i] = malloc(collumn * sizeof(char));
    }
    for (int i = 0; i < row; i++){
        for (int j = 0; j < collumn; j++) {
            thearray[i][j] = '_';
        }
    }

    char thechar = 'A';
    for (int i = 0; i < num-1; i++) {
        int currentx = xcoordinates[i];
        int currenty = ycoordinates[i];
        int nextx = xcoordinates[i+1];
        int nexty = ycoordinates[i+1];
        if (currentx < 0 || currenty < 0 || currentx >= row || currenty >= row){
            printf("%s", "Out of range");
            return 0;
        
    }
        int check = 0;
        if (currenty == nexty) {
            check = 1;
        }
        thearray[currentx][currenty] = thechar;
        thechar++;

        if (currenty > nexty) {
            for (int j = 1; j <= row; j++) {
                if (currenty - j <= nexty) {
                


                    currenty = currenty - j;
                    break;
                }
                else {
                    thearray[currentx][currenty - j] = '<';
                }
            }
        }
        if (currenty < nexty) {
            for (int j = 1; j <= row; j++) {
                if (currenty + j >= nexty) {
                    currenty = currenty + j;
                    break;
                }
                else {
                    thearray[currentx][currenty + j] = '>';
                }
            }
        }
    

        if (currentx < nextx) {
            if (check == 0) {
            for (int j = 0; j <= row; j++) {
                if (currentx + j >= nextx) {
                    
                    break;
                }
                else {
                    thearray[currentx + j][currenty] = 'v';
                }
            }
        }
        else {
            for (int j = 1; j <= row; j++) {
                if (currentx + j >= nextx) {
                    
                    break;
                }
                else {
                    thearray[currentx + j][currenty] = 'v';
                }
            }
        }
        }
        if (currentx > nextx) {
            if (check == 0) {
            for (int j = 0; j <= row; j++) {
                if (currentx - j <=nextx) {
                    break;
                }
                else {
                    thearray[currentx - j][currenty] = '^';
                }
            }
        }
        else {
            for (int j = 1; j <= row; j++) {
                if (currentx - j <=nextx) {
                    break;
                }
                else {
                    thearray[currentx - j][currenty] = '^';
                }
            }
        }
        }
        

        if (i == num -2 ) {
            thearray[nextx][nexty] = thechar;
        }
        
    }

    for (int i = 0; i < row; i++) {
        for (int  j = 0;  j < collumn; j++) {
            printf("%c", thearray[i][j]);
        }
        printf("\n");
    }
}