답안 #229759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229759 2020-05-06T09:44:08 Z Coder Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
129 ms 17612 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define PR(x) cerr << #x << "=" << (x) << endl;
const int MOD = 1000000007;
const double pi = atan(1.0)*4.0;
const double eps = 1e-8;
const int N = 501;
int i, j, k, m, n;
int a[N];


string s[N];
int DX[]={-1,0,1,0};
int DY[]={0,1,0,-1};
int d[N][N];
string H="NESW";
int main() {
    //freopen("x.in", "r", stdin);

    cin >> m >> n;
    F0(i, m) cin >> s[i];

    set<pair<int, pii>> S;
    CL(-1, d);
    d[0][0] = 0;
    S.insert(make_pair(0, pii(0, 0)));
    while (!S.empty()) {
        pii p = S.begin()->second;
        S.erase(S.begin());
        if (s[p.first][p.second] == 'X') continue;
        F0(k, 4) {
            int x = p.first + DX[k], y = p.second + DY[k];
            if (x < 0 || x >= m || y < 0 || y >= n) continue;

            int d0 = H.find(s[p.first][p.second]);
            int cost = (k - d0 + 4) % 4 + d[p.first][p.second];

            if (d[x][y] == -1 || d[x][y] > cost) {
                d[x][y] = cost;
                S.insert(make_pair(cost, pii(x, y)));
            }
        }
    }
    cout << d[m-1][n-1] << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 5 ms 1280 KB Output is correct
12 Correct 5 ms 1280 KB Output is correct
13 Correct 5 ms 1280 KB Output is correct
14 Correct 5 ms 1280 KB Output is correct
15 Correct 5 ms 1280 KB Output is correct
16 Correct 5 ms 1408 KB Output is correct
17 Correct 5 ms 1280 KB Output is correct
18 Correct 6 ms 1536 KB Output is correct
19 Correct 5 ms 1280 KB Output is correct
20 Correct 5 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 6 ms 1408 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1408 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1280 KB Output is correct
10 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 5 ms 1280 KB Output is correct
12 Correct 5 ms 1280 KB Output is correct
13 Correct 5 ms 1280 KB Output is correct
14 Correct 5 ms 1280 KB Output is correct
15 Correct 5 ms 1280 KB Output is correct
16 Correct 5 ms 1408 KB Output is correct
17 Correct 5 ms 1280 KB Output is correct
18 Correct 6 ms 1536 KB Output is correct
19 Correct 5 ms 1280 KB Output is correct
20 Correct 5 ms 1408 KB Output is correct
21 Correct 5 ms 1280 KB Output is correct
22 Correct 6 ms 1408 KB Output is correct
23 Correct 5 ms 1280 KB Output is correct
24 Correct 5 ms 1280 KB Output is correct
25 Correct 5 ms 1280 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 5 ms 1280 KB Output is correct
29 Correct 7 ms 1280 KB Output is correct
30 Correct 5 ms 1408 KB Output is correct
31 Correct 5 ms 1280 KB Output is correct
32 Correct 5 ms 1408 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 11 ms 1408 KB Output is correct
36 Correct 5 ms 1280 KB Output is correct
37 Correct 13 ms 1408 KB Output is correct
38 Correct 8 ms 1408 KB Output is correct
39 Correct 80 ms 2168 KB Output is correct
40 Correct 82 ms 2168 KB Output is correct
41 Correct 17 ms 2048 KB Output is correct
42 Correct 80 ms 2168 KB Output is correct
43 Correct 129 ms 17612 KB Output is correct
44 Correct 17 ms 2048 KB Output is correct