Submission #64528771


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;

int n, m, sx, sy, ex, ey;
char s[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2] = { -1, 0, 1, 0, 0, -1, 0, 1 };
int dis[maxn][maxn];

bool in_map(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
}

struct Node {
    int x, y;
};

struct Node2 {
    int x, y, dis;

    bool operator < (const Node2 & b) const {
        return dis > b.dis;
    }
};

void dijkstra() {
    priority_queue<Node2> que;
    memset(dis, -1, sizeof dis);
    dis[sx][sy] = 0;
    que.push({sx, sy, 0});
    while (!que.empty()) {
        Node2 u = que.top();
        que.pop();
        if (vis[u.x][u.y])
            continue;
        vis[u.x][u.y] = true;
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 2; j++) {
                int x = u.x + dir[i][0] * j;
                int y = u.y + dir[i][1] * j;
                int w = 1;
                if (j == 1 && in_map(x, y) && s[x][y] == '.')
                    w = 0;
                if (!in_map(x, y))
                    continue;
                if (dis[x][y] == -1 || dis[x][y] > dis[u.x][u.y] + w) {
                    dis[x][y] = dis[u.x][u.y] + w;
                    que.push({x, y, dis[x][y]});
                }
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", s[i]);
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    sx--, sy--, ex--, ey--;
    dijkstra();
    printf("%d\n", dis[ex][ey]);
    return 0;
}

Submission Info

Submission Time
Task D - Takahashi the Wall Breaker
User quanjun
Language C++ 17 (gcc 12.2)
Score 400
Code Size 1594 Byte
Status AC
Exec Time 137 ms
Memory 21636 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:57:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:59:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |         scanf("%s", s[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:60:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |     scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 34
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 2 ms 7640 KiB
example_01.txt AC 2 ms 7568 KiB
example_02.txt AC 2 ms 7568 KiB
example_03.txt AC 2 ms 7912 KiB
hand_00.txt AC 80 ms 9616 KiB
hand_01.txt AC 77 ms 9844 KiB
hand_02.txt AC 78 ms 9852 KiB
hand_03.txt AC 79 ms 9612 KiB
hand_04.txt AC 82 ms 9672 KiB
hand_05.txt AC 108 ms 15504 KiB
hand_06.txt AC 107 ms 15516 KiB
hand_07.txt AC 92 ms 21056 KiB
hand_08.txt AC 137 ms 21576 KiB
hand_09.txt AC 2 ms 7876 KiB
random_00.txt AC 83 ms 9768 KiB
random_01.txt AC 84 ms 9788 KiB
random_02.txt AC 83 ms 9692 KiB
random_03.txt AC 83 ms 9776 KiB
random_04.txt AC 75 ms 9532 KiB
random_05.txt AC 76 ms 9624 KiB
random_06.txt AC 123 ms 21488 KiB
random_07.txt AC 123 ms 21560 KiB
random_08.txt AC 129 ms 21608 KiB
random_09.txt AC 113 ms 21588 KiB
random_10.txt AC 118 ms 21636 KiB
random_11.txt AC 115 ms 21440 KiB
random_12.txt AC 87 ms 9788 KiB
random_13.txt AC 91 ms 9780 KiB
random_14.txt AC 83 ms 9744 KiB
random_15.txt AC 88 ms 9648 KiB
random_16.txt AC 92 ms 9732 KiB
random_17.txt AC 79 ms 9768 KiB
random_18.txt AC 80 ms 9632 KiB
random_19.txt AC 81 ms 9696 KiB