답안 #447636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447636 2021-07-27T07:29:53 Z idas Awesome Arrowland Adventure (eJOI19_adventure) C++11
50 / 100
13 ms 4428 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

const int N=610;

ll m, n, d[N][N], g[N][N];
bool v[N][N];
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> q;

/*
-1-X
0-N
1-E
2-S
3-W
*/

int c(char x)
{
    if(x=='X') return -1;
    if(x=='N') return 0;
    if(x=='E') return 1;
    if(x=='S') return 2;
    if(x=='W') return 3;
}

pii re(int p, int x, int y)
{
    if(p==0) return MP(x, y-1);
    if(p==1) return MP(x+1, y);
    if(p==2) return MP(x, y+1);
    if(p==3) return MP(x-1, y);
}

int main()
{
    setIO();
    cin >> m >> n;
    FOR(i, 0, m)
    {
        FOR(j, 0, n)
        {
            char x;
            cin >> x;
            g[j][i]=c(x);
        }
    }

    FOR(i, 0, m) FOR(j, 0, n) d[j][i]=INF;

    v[n-1][m-1]=true;
    d[0][0]=0;
    q.push(MP(0, MP(0, 0)));
    while(!q.empty())
    {
        ll k=q.top().F, x=q.top().S.F, y=q.top().S.S;
        if(!v[x][y])
        {
            v[x][y]=true;
            FOR(i, 0, 4)
            {
                int nx=re((g[x][y]+i)%4, x, y).F, ny=re((g[x][y]+i)%4, x, y).S;
                if(nx<0 || nx>=n || ny<0 || ny>=m || (g[nx][ny]==-1 && (nx!=n-1 || ny!=m-1))) continue;
                d[nx][ny]=min(d[nx][ny], k+i);
                q.push(MP(d[nx][ny], MP(nx, ny)));
            }
        }
        q.pop();
    }
    if(g[0][0]==-1){
        cout << -1 << '\n';
        return 0;
    }
    cout << (d[n-1][m-1]==INF?-1:d[n-1][m-1]);
}

Compilation message

adventure.cpp: In function 'int c(char)':
adventure.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^
adventure.cpp: In function 'pii re(int, int, int)':
adventure.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2892 KB Output is correct
2 Correct 1 ms 2124 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 3916 KB Output is correct
5 Correct 2 ms 3276 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3788 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2892 KB Output is correct
2 Correct 1 ms 2124 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 3916 KB Output is correct
5 Correct 2 ms 3276 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3788 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 2 ms 3020 KB Output is correct
13 Correct 2 ms 4428 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1612 KB Output is correct
20 Correct 2 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4300 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 2124 KB Output is correct
4 Correct 1 ms 1740 KB Output is correct
5 Correct 2 ms 3916 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 1 ms 1740 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2892 KB Output is correct
2 Correct 1 ms 2124 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 3916 KB Output is correct
5 Correct 2 ms 3276 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3788 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 2 ms 3020 KB Output is correct
13 Correct 2 ms 4428 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1612 KB Output is correct
20 Correct 2 ms 4300 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 4300 KB Output is correct
26 Correct 1 ms 716 KB Output is correct
27 Correct 1 ms 2124 KB Output is correct
28 Correct 1 ms 1740 KB Output is correct
29 Correct 2 ms 3916 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 1 ms 1740 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 1 ms 844 KB Output is correct
34 Correct 1 ms 716 KB Output is correct
35 Correct 11 ms 4136 KB Output is correct
36 Correct 3 ms 3148 KB Output is correct
37 Incorrect 13 ms 2904 KB Output isn't correct
38 Halted 0 ms 0 KB -