이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define int long long
int it[] = {0,0,1,-1};
int jt[] = {1,-1,0,0};
int f(char ch, char c) {
if(ch == 'S') {
if(c == 'E') return 3;
if(c == 'S') return 0;
if(c == 'W') return 1;
if(c == 'N') return 2;
}
if(ch == 'W') {
if(c == 'E') return 2;
if(c == 'S') return 3;
if(c == 'W') return 0;
if(c == 'N') return 1;
}
if(ch == 'E') {
if(c == 'E') return 0;
if(c == 'S') return 1;
if(c == 'W') return 2;
if(c == 'N') return 3;
}
if(ch == 'N') {
if(c == 'E') return 1;
if(c == 'S') return 2;
if(c == 'W') return 3;
if(c == 'N') return 0;
}
}
signed main () {
int n, m;
scanf("%lld%lld", &n, &m);
char a[n][m];
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) std::cin >> a[i][j];
}
std::priority_queue <std::pair <int,std::pair <int,int> > > q;
int d[n][m];
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) d[i][j] = (int)1e16;
}
q.push({0, {n-1, m-1}});
d[n-1][m-1] = 0;
while(!q.empty()) {
std::pair <int,int> v = q.top().second;
q.pop();
// printf("%lld %lld\n", v.first, v.second);
for(int i = 0; i < 4; i ++) {
int ni = v.first + it[i];
int nj = v.second + jt[i];
if(ni >= n || nj >= m || ni < 0 || nj < 0) continue;
if(a[ni][nj] == 'X') continue;
int cnt = 0;
if(it[i] == -1) {
cnt = f(a[ni][nj], 'S');
}else if(jt[i] == -1) {
cnt = f(a[ni][nj], 'E');
}else if(jt[i] == 1) {
cnt = f(a[ni][nj], 'W');
}else {
cnt = f(a[ni][nj], 'N');
}
if(d[ni][nj] > d[v.first][v.second] + cnt) {
d[ni][nj] = d[v.first][v.second] + cnt;
q.push({-d[ni][nj], {ni, nj}});
}
}
}
if(d[0][0] == (int)1e16) printf("-1");
else
printf("%lld", d[0][0]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
adventure.cpp: In function 'long long int f(char, char)':
adventure.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
33 | }
| ^
adventure.cpp: In function 'int main()':
adventure.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%lld%lld", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |