Submission

Status:

[PP-SSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: ZanTy

Problemset: Path Finding

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-09 13:06:31

#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<int> x(q), y(q);
    vector<string> arr(n, string(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;
        } else {
            arr[x[i]][y[i]] = (char)('A' + i);
        }
    }

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

    // ขอบเขตตัวอักษรสูงสุดที่ห้ามทับ (ตรงกับเงื่อนไขลูป k เดิมของคุณ)
    char max_protected_char = (char)('A' + q - 1);

    for (int i = 0; i < q - 1; i++) {
        int skip = 0;
        int state = 0;
        int x1 = x[i];
        int y1 = y[i];
        int x2 = x[i+1]; // ดึงจากจุดถัดไปได้เลย ไม่ต้องใช้ตัวแปร target
        int y2 = y[i+1];

        // 1. เดินแนวนอน
        if (y2 > y1) {
            for (int j = 1; y1 + j != y2; j++) {
                char current_char = arr[x1][y1 + j];
                // แทนที่ลูป k: ถ้าตัวอักษรไม่ใช่พี่ใหญ่ ('B' ถึงตัวสุดท้าย) ให้เปลี่ยนเป็น '>'
                if (current_char < 'B' || current_char > max_protected_char) {
                    arr[x1][y1 + j] = '>';
                }
            }
        } else if (y1 > y2) {
            for (int j = 1; y2 + j != y1; j++) {
                char current_char = arr[x1][y1 - j];
                if (current_char < 'B' || current_char > max_protected_char) {
                    arr[x1][y1 - j] = '<';
                }
            }
        }

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

        // 2. เดินแนวตั้ง
        if (x2 > x1) {
            for (int j = state; x1 + j != x2; j++) {
                char current_char = arr[x1 + j][y2];
                if (current_char < 'B' || current_char > max_protected_char) {
                    arr[x1 + j][y2] = 'v';
                }
            }
        } else if (x2 < x1) {
            for (int j = state; x2 + j != x1; j++) {
                char current_char = arr[x1 - j][y2];
                if (current_char < 'B' || current_char > max_protected_char) {
                    arr[x1 - j][y2] = '^';
                }
            }
        }
    }

    // แสดงผลลัพธ์
    for (int i = 0; i < n; i++) {
        cout << arr[i] << '\n';
    }

    return 0;
}