이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//author:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
const int MAXN = 100 + 5;
char matrix[MAXN][MAXN];
bool vis[MAXN][MAXN];
map <char, int> mp;
char get() {
char ch;
cin >> ch;
return ch;
}
void solve() {
int n, m;
cin >> n >> m;
int stx, sty, finx, finy;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
matrix[i][j] = get();
if(matrix[i][j] == 'o') {
stx = i;
sty = j;
} else if(matrix[i][j] == 'x') {
finx = i;
finy = j;
}
}
}
function <void(int, int)> dfs = [&](int x, int y) -> void {
if(vis[x][y])
return;
//cerr << x << " " << y << "\n";
vis[x][y] = true;
if(matrix[x][y] == '.' || x < 1 || x > n || y < 1 || y > m)
return;
if(matrix[x][y] == '>') {
dfs(x, y +1);
} else if(matrix[x][y] == 'v') {
dfs(x +1, y);
} else if(matrix[x][y] == '<') {
dfs(x, y -1);
} else if(matrix[x][y] == '^') {
dfs(x -1, y);
}
};
auto check = [&](int yon) -> bool {
memset(vis, false, sizeof(vis));
if(yon == 0) {
dfs(stx -1, sty);
} else if(yon == 1) {
dfs(stx, sty -1);
} else if(yon == 2) {
dfs(stx, sty +1);
} else {
dfs(stx +1, sty);
}
//cerr << "\n";
return vis[finx][finy];
};
mp['E'] = 2;
mp['N'] = 1;
mp['S'] = 3;
mp['W'] = 0;
for(auto &[ch, a] : mp) {
if(check(a)) {
cout << ":)\n";
cout << ch;
return;
}
}
cout << ":(";
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
while(t--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
patkice.cpp: In function 'void solve()':
patkice.cpp:75:30: warning: 'finy' may be used uninitialized in this function [-Wmaybe-uninitialized]
75 | return vis[finx][finy];
| ^
patkice.cpp:75:30: warning: 'finx' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:25:14: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
25 | int stx, sty, finx, finy;
| ^~~
patkice.cpp:64:16: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | dfs(stx -1, sty);
| ~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |