답안 #370095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370095 2021-02-23T08:38:31 Z AdamGS Awesome Arrowland Adventure (eJOI19_adventure) C++14
0 / 100
1 ms 396 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=507, INF=1e9+7;
string x[LIM];
int odl[LIM][LIM];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, n) cin >> x[i];
    deque<pair<pair<int,int>,int>>q;
    rep(i, n) rep(j, m) odl[i][j]=INF;
    q.push_front({{0, 0}, 0});
    while(!q.empty()) {
        int a=q.front().st.st, b=q.front().st.nd, o=q.front().nd;
        q.pop_front();
        if(o>=odl[a][b]) continue;
        odl[a][b]=o;
        if(a) {
            if(x[a][b]=='N') q.push_front({{a-1, b}, o});
            else if(x[a][b]=='W') q.push_back({{a-1, b}, o+1});
            else if(x[a][b]=='S') q.push_back({{a-1, b}, o+2});
            else if(x[a][b]=='E') q.push_back({{a-1, b}, o+3});
        }
        if(a<n-1) {
            if(x[a][b]=='S') q.push_front({{a+1, b}, o});
            else if(x[a][b]=='E') q.push_back({{a+1, b}, o+1});
            else if(x[a][b]=='N') q.push_back({{a+1, b}, o+2});
            else if(x[a][b]=='W') q.push_back({{a+1, b}, o+3});
        }
        if(b) {
            if(x[a][b]=='W') q.push_front({{a, b-1}, o});
            else if(x[a][b]=='S') q.push_back({{a, b-1}, o+1});
            else if(x[a][b]=='E') q.push_back({{a, b-1}, o+2});
            else if(x[a][b]=='N') q.push_back({{a, b-1}, o+3});
        }
        if(b<m-1) {
            if(x[a][b]=='E') q.push_front({{a, b+1}, o});
            else if(x[a][b]=='N') q.push_back({{a, b+1}, o+1});
            else if(x[a][b]=='W') q.push_back({{a, b+1}, o+2});
            else if(x[a][b]=='S') q.push_back({{a, b+1}, o+3});
        }
    }
    cout << odl[n-1][m-1] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -