이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define x first
#define y second
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
using namespace std;
typedef pair <int, int> ii;
const int maxn = 105;
int N, M;
char A[maxn][maxn];
int dfs(int u, int v) {
if (A[u][v] == 'o' || A[u][v] == '.') return -1;
if (A[u][v] == 'x') return 1;
int nu = u, nv = v;
if (A[u][v] == '<') --nv;
else if (A[u][v] == '>') ++nv;
else if (A[u][v] == 'v') ++nu;
else --nu;
int k = dfs(nu, nv);
if (k == -1) return -1;
return 1 + k;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen("cc.inp", "r", stdin);
// freopen("cc.out", "w", stdout);
cin >> N >> M;
int stx, sty;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cin >> A[i][j];
if (A[i][j] == 'o') {
stx = i;
sty = j;
}
}
}
int mn = (int)1e9;
char ans = 'Z';
int k = dfs(stx - 1, sty);
if (k != -1) {
if (k < mn) {
mn = k;
ans = 'N';
}
}
k = dfs(stx + 1, sty);
if (k != -1) {
if (k < mn) {
mn = k;
ans = 'S';
} else if (k == mn) {
ans = min(ans, 'S');
}
}
k = dfs(stx, sty - 1);
if (k != -1) {
if (k < mn) {
mn = k;
ans ='W';
} else if (k == mn) {
ans = min(ans, 'W');
}
}
k = dfs(stx, sty + 1);
if (k != -1) {
if (k < mn) {
mn = k;
ans ='E';
} else if (k == mn) {
ans = min(ans, 'E');
}
}
if (ans == 'Z') {
cout << ":(";
} else
cout << ":)\n" << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
patkice.cpp: In function 'int main()':
patkice.cpp:52:10: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | k = dfs(stx + 1, sty);
| ~~~^~~~~~~~~~~~~~
patkice.cpp:52:10: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |