#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,posi=0,posj=0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//scanf("%d %d",&r,&s);
cin >> r >> s;
char corr[r][s];
/*scanf("%c",&auxi);*/
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,j=posj+1,mini=1e6,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]=='x'){
xd=true;
break;
}else{
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]=='x'){
xd=true;
break;
}else{
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]=='x'){
xd=true;
break;
}else{
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]=='x'){
xd=true;
break;
}else{
break;
}
}
if(xd){
if(con<mini){
mini=con;
res='W';
}
}
if(res!='.'){
cout << ":)\n" << res;
//printf(":)\n");
//printf("%c",res);
}else{
cout << ":(";
//printf(":(");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |