#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const string str="SENW";
int n,m;
char s[105][105];
bool was[105][105];
bool valid(int x,int y){
return 1<=x&&x<=n&&1<=y&&y<=m;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
int sx,sy,fx,fy;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(s[i][j]=='o'){
sx=i;
sy=j;
}
if(s[i][j]=='x'){
fx=i;
fy=j;
}
}
}
char res='a';
int mn=10000;
for(int dir=0;dir<4;dir++){
if(!valid(sx+dx[dir],sy+dy[dir])){
continue;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
was[i][j]=false;
}
}
int cnt=1,cx=sx+dx[dir],cy=sy+dy[dir];
was[cx][cy]=true;
while(cx!=fx||cy!=fy){
int nx=cx,ny=cy;
if(s[cx][cy]=='^') nx=cx-1,ny=cy;
if(s[cx][cy]=='v') nx=cx+1,ny=cy;
if(s[cx][cy]=='<') nx=cx,ny=cy-1;
if(s[cx][cy]=='>') nx=cx,ny=cy+1;
if(!valid(nx,ny)||was[nx][ny]) break;
cnt++;
cx=nx;
cy=ny;
was[cx][cy]=true;
}
if(cx==fx&&cy==fy){
if(cnt<mn){
mn=cnt;
res=str[dir];
}else if(cnt==mn){
chkmin(res,str[dir]);
}
}
}
if(res=='a') printf(":(");
else printf(":)\n%c",res);
return 0;
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
patkice.cpp:39:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
| ~~~~~^~~~~~~~~~~~~
patkice.cpp:66:19: warning: 'fy' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | while(cx!=fx||cy!=fy){
| ~~^~~~
patkice.cpp:66:11: warning: 'fx' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | while(cx!=fx||cy!=fy){
| ~~^~~~
patkice.cpp:56:12: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | if(!valid(sx+dx[dir],sy+dy[dir])){
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:56:12: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
696 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |