Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Chayatoeyy
Problemset: Path Finding
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-15 09:16:11
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
vector<vector<char>> a(n,vector<char>(n,'_'));
int cnt=0,rr,rc;
bool out = false;
while(m>0){
int x,y;
cin>>x>>y;
if(x>=n || x<0 || y<0 || y>=n){
cout << "Out of range\n";
out = true;
}
if(cnt==0 && !out){
rr = x;
rc = y;
a[rr][rc]='A';
cnt++;
m--;
continue;
}
while(rc<y && !out){
rc++;
a[rr][rc] = '>';
}
while(rc>y && !out){
rc--;
a[rr][rc] = '<';
}
while(rr>x && !out){
rr--;
a[rr][rc]='^';
if(a[rr+1][rc]=='<' || a[rr+1][rc]=='>' || a[rr+1][rc]=='v'){
a[rr+1][rc] = '^';
}
}
while(rr<x && !out){
rr++;
a[rr][rc]='v';
if(a[rr-1][rc]=='<' || a[rr-1][rc]=='>' || a[rr-1][rc]=='v'){
a[rr-1][rc] = 'v';
}
}
if(!out){
a[x][y]='A'+cnt;
cnt++;
}
m--;
}
if(out){
return 0;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout << a[i][j];
}cout << endl;
}
}