Submission #11232040


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
using P = array<int, 2>;
const int dh[]{1, 0, -1, 0}, dw[]{0, 1, 0, -1};

int H, W;

inline bool in(int h, int w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main() {
    int N;
    ll A, B, C;
    cin >> H >> W >> A >> B >> C >> N;
    H++;
    W++;
    int d0[H][W];
    memset(d0, -1, sizeof(d0));
    queue<P> que;
    int sh, sw, th, tw;
    for(int i = 0; i < N; i++) {
        cin >> th >> tw;
        if(!i) sh = th, sw = tw;
        que.push(P{th, tw});
        d0[th][tw] = 0;
    }
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        for(int i = 0; i < 4; i++) {
            int nh = p[0] + dh[i];
            int nw = p[1] + dw[i];
            if(in(nh, nw) && d0[nh][nw] == -1) {
                d0[nh][nw] = d0[p[0]][p[1]] + 1;
                que.push(P{nh, nw});
            }
        }
    }

    V<V<V<ll>>> d(H, V<V<ll>>(W, V<ll>(5, 1LL << 60)));
    struct st {
        int h, w, v;
        ll d;
        inline bool operator<(const st &r) const { return d > r.d; }
    };
    d[sh][sw][4] = 0;
    priority_queue<st> pque;
    pque.push(st{sh, sw, 4, 0});
    while(!pque.empty()) {
        st v = pque.top();
        pque.pop();
        if(d[v.h][v.w][v.v] < v.d) continue;
        if(v.v == 4) {
            for(int i = 0; i < 4; i++) {
                int nh = v.h + dh[i];
                int nw = v.w + dw[i];
                if(in(nh, nw)) {
                    if(d[nh][nw][4] > v.d + C) {
                        d[nh][nw][4] = v.d + C;
                        pque.push(st{nh, nw, 4, v.d + C});
                    }
                    if(d[nh][nw][i] > v.d + A + B) {
                        d[nh][nw][i] = v.d + A + B;
                        pque.push(st{nh, nw, i, v.d + A + B});
                    }
                }
            }
        } else {
            int nh = v.h + dh[v.v];
            int nw = v.w + dw[v.v];
            if(in(nh, nw) && d[nh][nw][v.v] > v.d + A) {
                d[nh][nw][v.v] = v.d + A;
                pque.push(st{nh, nw, v.v, v.d + A});
            }
            if(d[v.h][v.w][4] > v.d + d0[v.h][v.w] * C) {
                d[v.h][v.w][4] = v.d + d0[v.h][v.w] * C;
                pque.push(st{v.h, v.w, 4, d[v.h][v.w][4]});
            }
        }
    }
    ll ans = 1LL << 60;
    for(int i = 0; i < 5; i++)
        ans = min(ans, d[th][tw][i]);
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - サッカー (Soccer)
User Series_205
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2580 Byte
Status AC
Exec Time 403 ms
Memory 27144 KB

Judge Result

Set Name Subtask01 Subtask02 Subtask03
Score / Max Score 5 / 5 30 / 30 65 / 65
Status
AC × 5
AC × 15
AC × 39
Set Name Test Cases
Subtask01 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, sample-02, sample-03
Subtask02 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, sample-02, sample-03, sample-04
Subtask03 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, 03-15.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 61 ms 6404 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 261 ms 27016 KB
01-04.txt AC 280 ms 26120 KB
01-05.txt AC 49 ms 7296 KB
02-01.txt AC 272 ms 26120 KB
02-02.txt AC 269 ms 25352 KB
02-03.txt AC 214 ms 23048 KB
02-04.txt AC 221 ms 26888 KB
02-05.txt AC 210 ms 23304 KB
02-06.txt AC 244 ms 25736 KB
02-07.txt AC 265 ms 25608 KB
02-08.txt AC 272 ms 25608 KB
02-09.txt AC 280 ms 25480 KB
02-10.txt AC 39 ms 4988 KB
02-11.txt AC 261 ms 27144 KB
02-12.txt AC 267 ms 25480 KB
02-13.txt AC 176 ms 23048 KB
02-14.txt AC 259 ms 26760 KB
02-15.txt AC 197 ms 22920 KB
03-01.txt AC 64 ms 7944 KB
03-02.txt AC 358 ms 27144 KB
03-03.txt AC 330 ms 20236 KB
03-04.txt AC 362 ms 23052 KB
03-05.txt AC 362 ms 25480 KB
03-06.txt AC 359 ms 27016 KB
03-07.txt AC 194 ms 19208 KB
03-08.txt AC 255 ms 19260 KB
03-09.txt AC 369 ms 22156 KB
03-10.txt AC 214 ms 19072 KB
03-11.txt AC 270 ms 27144 KB
03-12.txt AC 403 ms 25480 KB
03-13.txt AC 258 ms 26504 KB
03-14.txt AC 351 ms 26504 KB
03-15.txt AC 205 ms 19200 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB
sample-04.txt AC 1 ms 256 KB