Submission
Status:
[PP-SSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: SayRo
Problemset: Path Finding
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-08 14:59:51
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,t,sx=-1,sy=-1,ct=0;
bool flag=true;
queue<pair<int,int>> q;
cin>>n>>t;
vector<vector<char>> grid(n,vector<char>(n,'_'));
while(t--){
int x,y;
cin>>x>>y;
if(x<0||y<0||x>=n||y>=n) flag=false;
if(flag){
q.push({x,y});
grid[x][y]='A'+ct;
ct++;
}
}
if(!flag) cout<<"Out of range",exit(0);
ct=0;
while(!q.empty()){
auto [r,c]=q.front();
q.pop();
if(sx==-1&&sy==-1){
sx=c,sy=r;
continue;
}
while(sx!=c){
if(sx>c){
if(grid[sy][sx]!='A'+ct) grid[sy][sx]='<';
sx--;
}else{
if(grid[sy][sx]!='A'+ct) grid[sy][sx]='>';
sx++;
}
}
while(sy!=r){
if(sy>r){
if(grid[sy][sx]!='A'+ct) grid[sy][sx]='^';
sy--;
}else{
if(grid[sy][sx]!='A'+ct) grid[sy][sx]='v';
sy++;
}
}
sx=c,sy=r;
ct++;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<grid[i][j];
}
cout<<"\n";
}
}