Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: ZanTy
Problemset: Path Finding
Language: cpp
Time: 0.005 second
Submitted On: 2026-10-09 13:09:58
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int N, nPoint;
cin >> N >> nPoint;
vector<int> r(nPoint), c(nPoint);
bool ok = true;
for (int i = 0; i < nPoint; i++) {
cin >> r[i] >> c[i];
if (r[i] < 0 || r[i] >= N || c[i] < 0 || c[i] >= N)
ok = false;
}
if (!ok) {
cout << "Out of range" << endl;
return 0;
}
vector<string> g(N, string(N, '_'));
for (int i = 0; i + 1 < nPoint; i++) {
int r1 = r[i], c1 = c[i];
int r2 = r[i + 1], c2 = c[i + 1];
// เดินตามแนวนอน (เปลี่ยนค่า c) ก่อน บนแถว r1
if (c1 != c2) {
int step = (c2 > c1) ? 1 : -1;
char ch = (step > 0) ? '>' : '<';
for (int x = c1; x != c2; x += step)
g[r1][x] = ch;
}
// แล้วค่อยเดินตามแนวตั้ง (เปลี่ยนค่า r) บนหลัก c2
if (r1 != r2) {
int step = (r2 > r1) ? 1 : -1;
char ch = (step > 0) ? 'v' : '^';
for (int y = r1; y != r2; y += step)
g[y][c2] = ch;
}
// จุดเริ่มของเส้นทางนี้ใช้ตัวอักษรลำดับ
g[r1][c1] = 'A' + i;
}
// จุดสุดท้าย
if (nPoint > 0)
g[r[nPoint - 1]][c[nPoint - 1]] = 'A' + (nPoint - 1);
for (int i = 0; i < N; i++)
cout << g[i] << "\n";
return 0;
}