이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
//#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 2e5+1;
void solve() {
int n,m;
cin >> n >> m;
char grid[n+1][m+1];
int px,py;
F(i,n) {
string s;
cin >> s;
F(j,m) {
grid[i][j] = s[j-1];
if (grid[i][j] == 'o') px = i,py = j;
}
}
vector<char> dirs = {'E','W','N','S'};
vi dx = {0,0,-1,1};
vi dy = {1,-1,0,0};
int steps = 1e9;
string ans;
char ans2;
for (int i=0;i<4;i++) {
int x = px+dx[i];
int y = py+dy[i];
if (!(x <= n && x >= 1 && y <=m && y >= 1)) continue;
int haha = 0;
while (grid[x][y] != '.') {
haha++;
if (grid[x][y] == '>') y++;
else if (grid[x][y] == '<') y--;
else if (grid[x][y] == '^') x--;
else if (grid[x][y] == 'v') x++;
else break;
}
if (grid[x][y] == 'x') {
if (haha < steps || (haha == steps && ans2 > dirs[i])){
steps = haha;
ans = ":)\n";
ans2 = dirs[i];
}
}
}
if (ans[1] == ')') cout << ans << ans2 << endl;
else cout << ":(\n";
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
patkice.cpp: In function 'void solve()':
patkice.cpp:45:39: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | if (haha < steps || (haha == steps && ans2 > dirs[i])){
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
patkice.cpp:32:18: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
32 | int x = px+dx[i];
| ^
patkice.cpp:33:18: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
33 | int y = py+dy[i];
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |