Submission
Status:
PPPPPPPPPP
Score: 100
User: veerasaroot
Problemset: Path Finding
Language: cpp
Time: 0.003 second
Submitted On: 2025-01-05 20:55:37
#include <iostream>
#include <vector>
using namespace std;
void printMap(vector<vector<char>>& map, int N)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cout << map[i][j] << " ";
}
cout << endl;
}
}
int main()
{
int N, nPoint;
cin >> N >> nPoint;
vector<pair<int, int>> points(nPoint);
for (int i = 0; i < nPoint; i++)
{
cin >> points[i].first >> points[i].second;
}
for (const auto& point : points)
{
if (point.first < 0 || point.first >= N || point.second < 0 || point.second >= N)
{
cout << "Out of range" << endl;
return 0;
}
}
vector<vector<char>> map(N, vector<char>(N, '_'));
char currentChar = 'A';
for (int i = 0; i < nPoint - 1; i++)
{
int r1 = points[i].first;
int c1 = points[i].second;
int r2 = points[i + 1].first;
int c2 = points[i + 1].second;
map[r1][c1] = currentChar;
if (r1 != r2 && c1 != c2)
{
if (c1 < c2)
{
for (int j = c1 + 1; j <= c2 - 1; j++)
{
map[r1][j] = '>';
}
map[r1][c2] = (r1 < r2) ? 'v' : '^';
}
else
{
for (int j = c1 - 1; j >= c2 + 1; j--)
{
map[r1][j] = '<';
}
map[r1][c2] = (r1 < r2) ? 'v' : '^';
}
if (r1 < r2)
{
for (int j = r1 + 1; j < r2; j++)
{
map[j][c2] = 'v';
}
}
else
{
for (int j = r1 - 1; j > r2; j--)
{
map[j][c2] = '^';
}
}
}
else
{
if (r1 == r2)
{
if (c1 < c2)
{
for (int j = c1 + 1; j <= c2; j++)
{
map[r1][j] = '>';
}
}
else {
for (int j = c1 - 1; j >= c2; j--)
{
map[r1][j] = '<';
}
}
}
else
{
if (r1 < r2)
{
for (int j = r1 + 1; j <= r2; j++)
{
map[j][c1] = 'v';
}
}
else
{
for (int j = r1 - 1; j >= r2; j--)
{
map[j][c1] = '^';
}
}
}
}
currentChar++;
}
map[points[nPoint - 1].first][points[nPoint - 1].second] = currentChar;
printMap(map, N);
return 0;
}