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;
int r, s, col, row, mark[105][105];
pair<int, int> dir[4] = {{0, 1}, {-1, 0}, {1, 0}, {0, -1}};
pair<char, int> cevap;
char d[105][105];
pair<bool, int> check(int x, int y, int step){
if(mark[x][y]){
return {false, 0};
}
mark[x][y] = 1;
char ch = d[x][y];
pair<bool, int> ans;
switch (ch)
{
case 'x':
return {true, step};
break;
case '>':
ans = check(x, y + 1, step + 1);
break;
case '<':
ans = check(x, y - 1, step + 1);
break;
case 'v':
ans = check(x + 1, y, step + 1);
break;
case '^':
ans = check(x - 1, y, step + 1);
break;
default:
return {false, 0};
break;
}
return ans;
}
int main(){
cevap.second = INT_MAX;
cin >> r >> s;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < s; j++)
{
cin >> d[i][j];
if(d[i][j] == 'o'){
row = i;
col = j;
}
}
}
for (int i = 0; i < 4; i++)
{
pair<bool, int> temp = check(row + dir[i].first, col + dir[i].second, 1);
if(temp.first && temp.second < cevap.second){
cevap.second = temp.second;
switch (i)
{
case 0:
cevap.first = 'E';
break;
case 1:
cevap.first = 'N';
break;
case 2:
cevap.first = 'S';
break;
default:
cevap.first = 'W';
break;
}
}
memset(mark, 0, sizeof(mark));
}
if(cevap.first){
cout << ":)\n" << cevap.first;
}else{
cout << ":(";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |