답안 #153527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153527 2019-09-14T12:50:32 Z onjo0127 Dangerous Skating (JOI16_skating) C++11
100 / 100
887 ms 23664 KB
#include <bits/stdc++.h>
using namespace std;
using tiii = tuple<int, int, int>;

const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

char A[1009][1009];
int L[1009][1009], RR[1009][1009], U[1009][1009], D[1009][1009], S[1009][1009];

int main() {
    int R, C; scanf("%d%d",&R,&C);
    for(int i=1; i<=R; i++) {
        for(int j=1; j<=C; j++) {
            scanf(" %c", &A[i][j]);
            S[i][j] = 1e9;
        }
    }
    int xs, ys, xe, ye; scanf("%d%d%d%d",&xs,&ys,&xe,&ye);
    for(int i=1; i<=R; i++) {
        int ls = -1;
        for(int j=1; j<=C; j++) {
            if(A[i][j] == '#') ls = j+1;
            L[i][j] = ls;
        }
        for(int j=C; j>=1; j--) {
            if(A[i][j] == '#') ls = j-1;
            RR[i][j] = ls;
        }
    }
    for(int i=1; i<=C; i++) {
        int ls = -1;
        for(int j=1; j<=R; j++) {
            if(A[j][i] == '#') ls = j+1;
            U[j][i] = ls;
        }
        for(int j=R; j>=1; j--) {
            if(A[j][i] == '#') ls = j-1;
            D[j][i] = ls;
        }
    }
    S[xs][ys] = 0;
    priority_queue<tiii> pq; pq.push((tiii){0, xs, ys});
    while(pq.size()) {
        int d, x, y; tie(d, x, y) = pq.top(); d = -d; pq.pop();
        if(S[x][y] != d) continue;
        vector<tiii> nx;
        nx.push_back((tiii){d+1, x, L[x][y]});
        nx.push_back((tiii){d+1, x, RR[x][y]});
        nx.push_back((tiii){d+1, U[x][y], y});
        nx.push_back((tiii){d+1, D[x][y], y});
        for(int k=0; k<4; k++) {
            int X = x+dx[k], Y = y+dy[k];
            if(A[X][Y] != '#') nx.push_back((tiii){d+2, X, Y});
        }
        for(auto& it: nx) {
            int dd, xx, yy; tie(dd, xx, yy) = it;
            if(S[xx][yy] > dd) {
                S[xx][yy] = dd;
                pq.push((tiii){-dd, xx, yy});
            }
        }
    }
    if(S[xe][ye] == 1e9) puts("-1");
    else printf("%d", S[xe][ye]);
    return 0;
}

Compilation message

skating.cpp: In function 'int main()':
skating.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int R, C; scanf("%d%d",&R,&C);
               ~~~~~^~~~~~~~~~~~~~
skating.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &A[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
skating.cpp:19:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int xs, ys, xe, ye; scanf("%d%d%d%d",&xs,&ys,&xe,&ye);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 736 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 736 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 23 ms 4520 KB Output is correct
12 Correct 24 ms 4708 KB Output is correct
13 Correct 24 ms 4732 KB Output is correct
14 Correct 20 ms 4600 KB Output is correct
15 Correct 8 ms 4472 KB Output is correct
16 Correct 24 ms 4728 KB Output is correct
17 Correct 19 ms 4600 KB Output is correct
18 Correct 16 ms 4472 KB Output is correct
19 Correct 20 ms 4600 KB Output is correct
20 Correct 21 ms 4344 KB Output is correct
21 Correct 14 ms 4472 KB Output is correct
22 Correct 10 ms 4600 KB Output is correct
23 Correct 18 ms 4600 KB Output is correct
24 Correct 22 ms 4600 KB Output is correct
25 Correct 16 ms 4572 KB Output is correct
26 Correct 17 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 736 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 528 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 23 ms 4520 KB Output is correct
12 Correct 24 ms 4708 KB Output is correct
13 Correct 24 ms 4732 KB Output is correct
14 Correct 20 ms 4600 KB Output is correct
15 Correct 8 ms 4472 KB Output is correct
16 Correct 24 ms 4728 KB Output is correct
17 Correct 19 ms 4600 KB Output is correct
18 Correct 16 ms 4472 KB Output is correct
19 Correct 20 ms 4600 KB Output is correct
20 Correct 21 ms 4344 KB Output is correct
21 Correct 14 ms 4472 KB Output is correct
22 Correct 10 ms 4600 KB Output is correct
23 Correct 18 ms 4600 KB Output is correct
24 Correct 22 ms 4600 KB Output is correct
25 Correct 16 ms 4572 KB Output is correct
26 Correct 17 ms 4472 KB Output is correct
27 Correct 759 ms 22500 KB Output is correct
28 Correct 860 ms 23024 KB Output is correct
29 Correct 853 ms 23664 KB Output is correct
30 Correct 710 ms 22728 KB Output is correct
31 Correct 89 ms 22008 KB Output is correct
32 Correct 542 ms 22176 KB Output is correct
33 Correct 108 ms 11000 KB Output is correct
34 Correct 219 ms 22140 KB Output is correct
35 Correct 496 ms 22496 KB Output is correct
36 Correct 385 ms 22332 KB Output is correct
37 Correct 171 ms 22268 KB Output is correct
38 Correct 887 ms 23128 KB Output is correct
39 Correct 293 ms 21980 KB Output is correct
40 Correct 167 ms 22008 KB Output is correct