#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define MOD 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FIN "\n"
#define REP(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) x.begin(),x.end();
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
int r,s;
char auxi;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//scanf("%d %d",&r,&s);
cin >> r >> s;
char corr[r][s];
/*scanf("%c",&auxi);*/
int posi;
int posj;
for(int i=0;i<r;i++){
for(int j=0;j<s;j++){
//scanf("%c",&corr[i][j]);
cin >> corr[i][j];
if(corr[i][j]=='o'){
posi=i;
posj=j;
}
}
}
int i=posi;
int j=posj+1;
int mini=1e9;
int con=0;
bool xd=false;
char res='.';
while(true){
con++;
if(corr[i][j]=='^'){
i--;
}else if(corr[i][j]=='v'){
i++;
}else if(corr[i][j]=='<'){
j--;
}else if(corr[i][j]=='>'){
j++;
}else if(corr[i][j]=='.'){
break;
}else if(corr[i][j]=='x'){
xd=true;
break;
}
}
if(xd){
res='E';
mini=con;
}
i=posi-1;
j=posj;
con=0;
xd=false;
while(true){
con++;
if(corr[i][j]=='^'){
i--;
}else if(corr[i][j]=='v'){
i++;
}else if(corr[i][j]=='<'){
j--;
}else if(corr[i][j]=='>'){
j++;
}else if(corr[i][j]=='.'){
break;
}else if(corr[i][j]=='x'){
xd=true;
break;
}
}
if(xd){
if(con<mini){
mini=con;
res='N';
}
}
i=posi+1;
j=posj;
con=0;
xd=false;
while(true){
con++;
if(corr[i][j]=='^'){
i--;
}else if(corr[i][j]=='v'){
i++;
}else if(corr[i][j]=='<'){
j--;
}else if(corr[i][j]=='>'){
j++;
}else if(corr[i][j]=='.'){
break;
}else if(corr[i][j]=='x'){
xd=true;
break;
}
}
if(xd){
if(con<mini){
mini=con;
res='S';
}
}
i=posi;
j=posj-1;
con=0;
xd=false;
while(true){
con++;
if(corr[i][j]=='^'){
i--;
}else if(corr[i][j]=='v'){
i++;
}else if(corr[i][j]=='<'){
j--;
}else if(corr[i][j]=='>'){
j++;
}else if(corr[i][j]=='.'){
break;
}else if(corr[i][j]=='x'){
xd=true;
break;
}
}
if(xd){
if(con<mini){
mini=con;
res='W';
}
}
if(res!='.'){
printf(":)\n");
printf("%c",res);
}else{
printf(":(");
}
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:49:21: warning: 'posi' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if(corr[i][j]=='^'){
| ~~~~~~~~~^
patkice.cpp:42:9: warning: 'posj' may be used uninitialized in this function [-Wmaybe-uninitialized]
42 | int j=posj+1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |