Submission

Status:

[PP-SSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: ZanTy

Problemset: Path Finding

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-08 14:09:58

#include <bits/stdc++.h>
using namespace std;

int main(){
    // ?Դ Fast I/O ???????????ҹ????ʴ??ŵ??ҧ??Ҵ?˭????Ǣ???ҡ
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n, q;
    if (!(cin >> n >> q)) return 0;

    // ?? vector ᷹ array Ẻ??? ???????ͧ˹??¤????Ӻ? Heap ??ͧ?ѹ Stack Overflow ?ࡳ?? 16MB
    vector<int> targetx(q);
    vector<int> targety(q);
    vector<int> x(q);
    vector<int> y(q);
    vector<vector<char>> arr(n, vector<char>(n, '_'));

    int cancel = 0;
    for (int i = 0; i < q; i++){
        cin >> x[i] >> y[i];
        if (0 > x[i] || x[i] >= n || 0 > y[i] || y[i] >= n){
            cancel = 1;
        }
        // ??ͧ?ѹ?Ѫ????ش?ͺ???ҧ??͹??????㹵??ҧ
        if (!cancel) {
            arr[x[i]][y[i]] = char('A' + i);
        }
        if (i >= 1){
            targetx[i-1] = x[i];
            targety[i-1] = y[i];
        }
    }

    if (cancel){
        cout << "Out of range\n";
        return 0;
    }

    for (int i = 0; i < q - 1; i++){
        int state = 0;
        int sex = 0;
        int x1 = x[i];
        int y1 = y[i];
        int x2 = targetx[i];
        int y2 = targety[i];

        // ?Ҵ??鹷ҧ?ǹ͹
        if (y2 > y1){
            sex = 1;
            for (int j = 1; y1 + j != y2; j++){
                // ?礴??? ASCII ᷹?ٻ k ??? (?????? O(1) ?ѹ?? ???Դ TLE)
                if (arr[x1][y1+j] >= 'A' && arr[x1][y1+j] <= 'Z'){
                    // ??ʶҹ???蹢?ҧ ????ͧ??¹?Ѻ
                } else {
                    arr[x1][y1+j] = '>'; sex++;
                }
            }
        }
        else if (y1 > y2){
            sex = 1;
            for (int j = 1; y2 + j != y1; j++){
                if (arr[x1][y1-j] >= 'A' && arr[x1][y1-j] <= 'Z'){
                    // ??ʶҹ???蹢?ҧ
                } else {
                    arr[x1][y1-j] = '<'; sex++;
                }
            }
        }

        if (y2 == y1){
            state = 1;
        }

        // ?Ҵ??鹷ҧ?ǵ??
        if (x2 > x1){
            for (int j = state; x1 + j != x2; j++){
                if (arr[x1+j][y2] >= 'A' && arr[x1+j][y2] <= 'Z'){
                    // ??ʶҹ???蹢?ҧ
                } else {
                    arr[x1+j][y2] = 'v';
                }
            }
        }
        else if (x2 < x1){
            for (int j = state; x2 + j != x1; j++){
                if (arr[x1-j][y2] >= 'A' && arr[x1-j][y2] <= 'Z'){
                    // ??ʶҹ???蹢?ҧ
                } else {
                    arr[x1-j][y2] = '^';
                }
            }
        }
    }

    // ?ʴ??ŵ??ҧ?Ѿ??
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            cout << arr[i][j];
        }
        cout << '\n';
    }
    return 0;
}