Submission #64525125


Source Code Expand

#include <bits/stdc++.h>
#define rg register
using namespace std;
const int N = 2e6 + 10;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9')
        f = (c == '-') ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9')
        x = x * 10 + c - 48, c = getchar();
    return f * x;
}
struct node {
    int v, id;
    bool operator<(const node& z) const { return v > z.v; }
};
struct node1 {
    int to, next, v;
} a[N * 4];
int dis[N], vis[N], head[N], cnt;
priority_queue<node> q;
void add(int x, int y, int v) {
    a[++cnt].next = head[x];
    a[cnt].to = y;
    a[cnt].v = v;
    head[x] = cnt;
}
void dij(int s) {
    q.push((node){0, s});
    memset(dis, 127, sizeof(dis));
    dis[s] = 0;
    while(!q.empty()) {
        int now = q.top().id;
        q.pop();
        if(vis[now])
            continue;
        vis[now] = 1;
        for(int i = head[now]; i; i = a[i].next) {
            int v = a[i].to;
            if(dis[v] > dis[now] + a[i].v)
                dis[v] = dis[now] + a[i].v, q.push((node){dis[v], v});
        }
    }
}
int n, m;
int calc(int x, int y) {
    return (x - 1) * m + y;
}
string s[1010];
int fx[10] = {0, 0, -1, 1, 0, 0, 2, -2};
int fy[10] = {1, -1, 0, 0, -2, 2, 0, 0};
int main() {
    n = read(), m = read();
    for(int i = 1; i <= n; i++) {
        cin >> s[i];
        s[i] = " " + s[i];
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            for(int k = 0; k <= 7; k++) {
                int x = fx[k] + i, y = fy[k] + j;
                if(x < 1 || y < 1 || x > n || y > m)
                    continue;
                if(s[x][y] == '#' || k >= 4)
                    add(calc(i, j), calc(x, y), 1);
                else
                    add(calc(i, j), calc(x, y), 0);
            }
        }
    int A = read(), B = read(), C = read(), D = read();
    dij(calc(A, B));
    cout << dis[calc(C, D)];
}

Submission Info

Submission Time
Task D - Takahashi the Wall Breaker
User hbx
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1994 Byte
Status AC
Exec Time 324 ms
Memory 121476 KiB

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 4 ms 11332 KiB
example_01.txt AC 4 ms 11448 KiB
example_02.txt AC 4 ms 11364 KiB
example_03.txt AC 4 ms 11412 KiB
hand_00.txt AC 204 ms 113836 KiB
hand_01.txt AC 204 ms 113888 KiB
hand_02.txt AC 205 ms 113880 KiB
hand_03.txt AC 203 ms 113832 KiB
hand_04.txt AC 203 ms 113800 KiB
hand_05.txt AC 212 ms 117556 KiB
hand_06.txt AC 218 ms 117620 KiB
hand_07.txt AC 140 ms 121476 KiB
hand_08.txt AC 259 ms 121156 KiB
hand_09.txt AC 4 ms 11360 KiB
random_00.txt AC 195 ms 107888 KiB
random_01.txt AC 168 ms 106100 KiB
random_02.txt AC 185 ms 110220 KiB
random_03.txt AC 198 ms 109516 KiB
random_04.txt AC 157 ms 103892 KiB
random_05.txt AC 156 ms 104768 KiB
random_06.txt AC 324 ms 117868 KiB
random_07.txt AC 320 ms 118608 KiB
random_08.txt AC 302 ms 119424 KiB
random_09.txt AC 314 ms 113932 KiB
random_10.txt AC 306 ms 113944 KiB
random_11.txt AC 323 ms 115084 KiB
random_12.txt AC 197 ms 109908 KiB
random_13.txt AC 212 ms 108880 KiB
random_14.txt AC 206 ms 106856 KiB
random_15.txt AC 209 ms 111860 KiB
random_16.txt AC 221 ms 109452 KiB
random_17.txt AC 191 ms 107776 KiB
random_18.txt AC 159 ms 108652 KiB
random_19.txt AC 175 ms 110096 KiB