Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: cyblox_boi
Problemset: Path Finding
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-23 00:24:37
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<string> path(n, string(n, '_'));
char currentChar = 'A';
bool isOutOfRange = false;
int prevA = -1, prevB = -1;
for (int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
if (a < 0 || a >= n || b < 0 || b >= n) {
isOutOfRange = true;
}
if (!isOutOfRange) {
if (i > 0) {
int x = prevA, y = prevB;
while (y != b) {
int nextY = y + (b > y ? 1 : -1);
if (nextY == b && a != prevA) {
path[x][nextY] = (a > x ? 'v' : '^');
y = nextY;
break;
}
path[x][nextY] = (b > y ? '>' : '<');
y = nextY;
}
while (x != a) {
int nextX = x + (a > x ? 1 : -1);
path[nextX][y] = (a > x ? 'v' : '^');
x = nextX;
}
}
path[a][b] = currentChar;
currentChar = (currentChar == 'Z' ? 'A' : currentChar + 1);
prevA = a;
prevB = b;
}
}
if (isOutOfRange) {
cout << "Out of range" << '\n';
} else {
for (const string &row : path) {
cout << row << '\n';
}
}
return 0;
}