Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: kavin8888
Problemset: Path Finding
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-15 21:47:33
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> pos(q);
bool outOfRange = false;
for (int i = 0; i < q; i++) {
cin >> pos[i].first >> pos[i].second;
if (pos[i].first < 0 || pos[i].second >= n || pos[i].second < 0 || pos[i].second >= n) {
outOfRange = true;
}
}
if (outOfRange) {
cout << "Out of range\n";
return 0;
}
// Create Canva
string tmp = "";
for (int i = 0; i < n; i++) {
tmp += "_";
}
vector<string> out(n, tmp);
// Edit Canva
out[pos[0].first][pos[0].second] = 'A';
for (int i = 1; i < q; i++) {
// Move Right
if (pos[i].second > pos[i - 1].second) {
for (int j = pos[i - 1].second + 1; j < pos[i].second; j++) {
out[pos[i - 1].first][j] = '>';
}
}
// Move Left
else if (pos[i].second < pos[i - 1].second) {
for (int j = pos[i - 1].second - 1; j > pos[i].second; j--) {
out[pos[i - 1].first][j] = '<';
}
}
// Move Down
if (pos[i].first > pos[i - 1].first) {
if (pos[i - 1].second != pos[i].second) {
out[pos[i - 1].first][pos[i].second] = 'v';
}
for (int j = pos[i - 1].first + 1; j < pos[i].first; j++) {
out[j][pos[i].second] = 'v';
}
}
// Move Up
else if (pos[i].first < pos[i - 1].first) {
if (pos[i - 1].second != pos[i].second) {
out[pos[i - 1].first][pos[i].second] = '^';
}
for (int j = pos[i - 1].first - 1; j > pos[i].first; j--) {
out[j][pos[i].second] = '^';
}
}
out[pos[i].first][pos[i].second] = 'A' + i;
}
// Print Output
for (int i = 0; i < out.size(); i++) {
cout << out[i] << '\n';
}
return 0;
}