Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: gay69
Problemset: Path Finding
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-12 08:33:58
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, q;
cin >> n >> q;
char arr[n][n];
fill_n(arr[0], n * n, '_');
int prev_x = -1, prev_y = -1;
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
if (x < 0 || y < 0 || x > n - 1 || y > n - 1) {
cout << "Out of range";
exit(0);
}
arr[x][y] = 'A' + i;
if (prev_x == -1 || prev_y == -1) {
prev_x = x, prev_y = y;
continue;
}
while (prev_y > y) {
if (arr[prev_x][prev_y] != 'A' + i - 1) {
arr[prev_x][prev_y] = '<';
}
prev_y--;
}
while (prev_y < y) {
if (arr[prev_x][prev_y] != 'A' + i - 1) {
arr[prev_x][prev_y] = '>';
}
prev_y++;
}
while (prev_x > x) {
if (arr[prev_x][prev_y] != 'A' + i - 1) {
arr[prev_x][prev_y] = '^';
}
prev_x--;
}
while (prev_x < x) {
if (arr[prev_x][prev_y] != 'A' + i - 1) {
arr[prev_x][prev_y] = 'v';
}
prev_x++;
}
prev_x = x, prev_y = y;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << arr[i][j];
}
cout << "\n";
}
return 0;
}