#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=2e5+10,M=3e3+10,mod=1e9+7;
int idx[4]={0,0,-1,1};
int idy[4]={1,-1,0,0};
char x[4]={'E','W','N','S'};
int ans[150][150],n,m;
string s[N];
bool inside(int x,int y){
return ((x>=0)&&(x<n)&&(y<m)&&(y>=0)&&(ans[x][y]==-1e18));
}
void floodfill(int x,int y,int type){
if(s[x][y]=='x')
return ;
else if(s[x][y]=='>'){
if(!inside(x,y+1))
return ;
ans[x][y+1]=ans[x][y]+1;
floodfill(x,y+1,type);
}
else if(s[x][y]=='<'){
if(!inside(x,y-1))
return ;
ans[x][y-1]=ans[x][y]+1;
floodfill(x,y-1,type);
}
else if(s[x][y]=='v'){
if(!inside(x+1,y))
return ;
ans[x+1][y]=ans[x][y]+1;
floodfill(x+1,y,type);
}
else if(s[x][y]=='^'){
if(!inside(x-1,y))
return ;
ans[x-1][y]=ans[x][y]+1;
floodfill(x-1,y,type);
}
else{
int newx=x+idx[type];
int newy=y+idy[type];
if(!inside(newx,newy))
return ;
ans[newx][newy]=ans[x][y]+1;
floodfill(newx,newy,type);
}
}
main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>s[i];
int indexx,indexy;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(s[i][j]=='o')
indexx=i,indexy=j;
int indexx2,indexy2;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(s[i][j]=='x')
indexx2=i,indexy2=j;
vector<pair<int,char>>v;
for(int i=0;i<4;i++){
for(int j=0;j<n;j++)
for(int k=0;k<m;k++)
ans[j][k]=-1e18;
ans[indexx][indexy]=0;
floodfill(indexx,indexy,i);
if(ans[indexx2][indexy2]!=-1e18)
v.pb({ans[indexx2][indexy2],x[i]});
}
if(v.size()==0){
cout<<":("<<endl;
return 0;
}
sort(v.begin(),v.end());
cout<<":)"<<endl;
cout<<v[0].S<<endl;
return 0;
}
Compilation message
patkice.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
77 | main()
| ^~~~
patkice.cpp: In function 'int main()':
patkice.cpp:107:18: warning: 'indexy' may be used uninitialized in this function [-Wmaybe-uninitialized]
107 | floodfill(indexx,indexy,i);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~
patkice.cpp:107:18: warning: 'indexx' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:109:32: warning: 'indexy2' may be used uninitialized in this function [-Wmaybe-uninitialized]
109 | if(ans[indexx2][indexy2]!=-1e18)
| ~~~~~~~~~~~~~~~~~~~~^
patkice.cpp:109:32: warning: 'indexx2' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6612 KB |
Output is correct |
2 |
Correct |
5 ms |
6568 KB |
Output is correct |
3 |
Correct |
5 ms |
6612 KB |
Output is correct |
4 |
Correct |
4 ms |
6636 KB |
Output is correct |
5 |
Correct |
3 ms |
6612 KB |
Output is correct |
6 |
Correct |
4 ms |
6484 KB |
Output is correct |
7 |
Correct |
4 ms |
6484 KB |
Output is correct |
8 |
Correct |
4 ms |
6612 KB |
Output is correct |
9 |
Correct |
4 ms |
6564 KB |
Output is correct |
10 |
Correct |
5 ms |
6572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6564 KB |
Output is correct |
2 |
Correct |
4 ms |
6612 KB |
Output is correct |
3 |
Correct |
4 ms |
6532 KB |
Output is correct |
4 |
Correct |
5 ms |
6612 KB |
Output is correct |
5 |
Correct |
4 ms |
6612 KB |
Output is correct |
6 |
Correct |
4 ms |
6500 KB |
Output is correct |
7 |
Correct |
5 ms |
6612 KB |
Output is correct |
8 |
Incorrect |
4 ms |
6612 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |