This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};
const char CH[5] = "WNES";
const int maxn = 105;
int n, m;
int dis[maxn][maxn];
char s[maxn][maxn];
vector<pair<int, char> > vec;
int main(){
//freopen("patkice.in", "r", stdin);
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%s", s[i]);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
if(s[i][j] == 'o'){
for(int k = 0; k < 4; ++k){
memset(dis, -1, sizeof(dis));
dis[i][j] = 0; int cur = 1, x, y;
for(x = i + dx[k], y = j + dy[k]; x >= 0 && x < n && y >= 0 && y < m && !~dis[x][y] && s[x][y] != '.' && s[x][y] != 'x'; ++cur){
dis[x][y] = cur;
if(s[x][y] == '<')
--y;
else if(s[x][y] == '>')
++y;
else if(s[x][y] == '^')
--x;
else
++x;
}
if(s[x][y] == 'x')
vec.PB(MP(cur, CH[k]));
}
}
sort(vec.begin(), vec.end());
if(!vec.size())
puts(":(");
else
puts(":)"), putchar(vec[0].snd);
return 0;
}
Compilation message (stderr)
patkice.cpp: In function 'int main()':
patkice.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
patkice.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%s", s[i]);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |