Submission

Status:

[PxSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: Bestzu

Problemset: Path Finding

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-16 09:24:27

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n; cin >> n;
    vector<pair<int,int>> point;
    vector<vector<char>> arr(n, vector<char>(n, '_'));
    
    int npoint; cin >> npoint;
    char ch = 'A';
    
    for(int i = 0; i < npoint; i++) {
        int r, c; cin >> r >> c;
        arr[r][c] = ch + i; // mark letter
        point.push_back({r, c});
    }

    for(int k = 0; k < npoint-1; k++) {
        int si = point[k].first;
        int sj = point[k].second;
        int vi = point[k+1].first;
        int vj = point[k+1].second;

        // move horizontally first
        if(sj < vj) { // move right
            for(int j = sj+1; j < vj; j++) {
                arr[si][j] = '>';
            }
        } 
        else if(sj > vj) { // move left
            for(int j = sj-1; j > vj; j--) {
                arr[si][j] = '<';
            }
        }

        // then move vertically
        if(si < vi) { // move down
            for(int i = si; i < vi; i++) {
                arr[i][vj] = 'v';
            }
        } 
        else if(si > vi) { // move up
            for(int i = si; i > vi; i--) {
                arr[i][vj] = '^';
            }
        }
    }

    // print result
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) cout << arr[i][j];
        cout << endl;
    }

    return 0;
}