Submission

Status:

[PP-SSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: cyblox_boi

Problemset: Path Finding

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-23 00:19:36

#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) {
			path[a][b] = currentChar;
			currentChar = (currentChar == 'Z' ? 'A' : currentChar + 1);

			if (i > 0) {
				int x = prevA, y = prevB;

				while (y != b) {
					int nextY = y + (b > y ? 1 : -1);

					if (toascii(path[x][nextY]) >= 65 &&
					    toascii(path[x][nextY]) <= 90) {
						y = nextY;
						continue;
					}

					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);

					if (toascii(path[nextX][y]) >= 65 &&
					    toascii(path[nextX][y]) <= 90) {
						x = nextX;
						continue;
					}

					path[nextX][y] = (a > x ? 'v' : '^');
					x = nextX;
				}
			}

			prevA = a;
			prevB = b;
		}
	}

	if (isOutOfRange) {
		cout << "Out of range" << '\n';
	} else {
		for (const string &row : path) {
			cout << row << '\n';
		}
	}

	return 0;
}