Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: loop
Problemset: Path Finding
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-10 18:34:18
#include <iostream>
#include <string>
using namespace std;
// Each move goes along the row first (changing c), then along the column (changing r). Every cell the move
// passes through shows the direction of the step that leaves it; the end cell gets the next letter.
int main() {
int n, k, r[105], c[105];
cin >> n >> k;
bool out = false;
for (int i = 0; i < k; i++) {
cin >> r[i] >> c[i];
if (r[i] < 0 || r[i] >= n || c[i] < 0 || c[i] >= n) out = true;
}
if (out) { cout << "Out of range" << '\n'; return 0; }
string g[105];
for (int i = 0; i < n; i++) g[i] = string(n, '_');
if (k > 0) g[r[0]][c[0]] = 'A';
for (int i = 1; i < k; i++) {
int y = r[i - 1], x = c[i - 1];
while (x != c[i]) {
int nx = x + (c[i] > x ? 1 : -1);
if (!(y == r[i - 1] && x == c[i - 1])) g[y][x] = c[i] > x ? '>' : '<';
x = nx;
}
while (y != r[i]) {
int ny = y + (r[i] > y ? 1 : -1);
if (!(y == r[i - 1] && x == c[i - 1])) g[y][x] = r[i] > y ? 'v' : '^';
y = ny;
}
g[y][x] = char('A' + i);
}
for (int i = 0; i < n; i++) cout << g[i] << '\n';
return 0;
}