Submission #22208662


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/












int H, W, A[505][505], B[505][505];
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int vis[505][505];
ll D[505][505];
ll dijk() {
    rep(y, 0, H) rep(x, 0, W) D[y][x] = infl;
    rep(y, 0, H) rep(x, 0, W) vis[y][x] = 0;

    min_priority_queue<pair<ll, int>> que;

    D[0][0] = 0;
    que.push({ 0, 0 });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll cst = q.first;
        int x = q.second % W;
        int y = q.second / W;

        if (x == W - 1 && y == H - 1) return cst;

        if (vis[y][x]) continue;
        vis[y][x] = 1;

        if (x < W - 1) if (chmin(D[y][x + 1], cst + A[y][x])) que.push({ D[y][x + 1], y * W + x + 1 });
        if (0 < x) if (chmin(D[y][x - 1], cst + A[y][x - 1])) que.push({ D[y][x - 1], y * W + x - 1 });
        if (y < H - 1) if (chmin(D[y + 1][x], cst + B[y][x])) que.push({ D[y + 1][x], (y + 1) * W + x });
        rep(dy, 1, y + 1) if (chmin(D[y - dy][x], cst + 1 + dy)) que.push({ D[y - dy][x], (y - dy) * W + x });
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) rep(x, 0, W - 1) cin >> A[y][x];
    rep(y, 0, H - 1) rep(x, 0, W) cin >> B[y][x];

    cout << dijk() << endl;
}





Submission Info

Submission Time
Task E - Sneaking
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 2739 Byte
Status AC
Exec Time 180 ms
Memory 8724 KiB

Compile Error

./Main.cpp: In function ‘ll dijk()’:
./Main.cpp:43:39: warning: control reaches end of non-void function [-Wreturn-type]
   43 |     min_priority_queue<pair<ll, int>> que;
      |                                       ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 01_sample.txt, 02_sample.txt, 03_sample.txt
All 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_random.txt, 05_random.txt, 06_random.txt, 07_random.txt, 08_random.txt, 09_random.txt, 10_random.txt, 11_random.txt, 12_random.txt, 13_random.txt, 14_random.txt, 15_random.txt, 16_random.txt, 17_random.txt, 18_random.txt, 19_random.txt, 20_random.txt, 21_random.txt, 22_random.txt, 23_random.txt, 24_max.txt, 25_max.txt, 26_max.txt, 27_max.txt, 28_zigzag.txt, 29_zigzag.txt
Case Name Status Exec Time Memory
01_sample.txt AC 7 ms 3656 KiB
02_sample.txt AC 3 ms 3652 KiB
03_sample.txt AC 3 ms 3596 KiB
04_random.txt AC 3 ms 3980 KiB
05_random.txt AC 19 ms 6156 KiB
06_random.txt AC 6 ms 5412 KiB
07_random.txt AC 2 ms 3644 KiB
08_random.txt AC 2 ms 3612 KiB
09_random.txt AC 7 ms 3780 KiB
10_random.txt AC 2 ms 3692 KiB
11_random.txt AC 20 ms 5848 KiB
12_random.txt AC 8 ms 4044 KiB
13_random.txt AC 66 ms 6256 KiB
14_random.txt AC 13 ms 4384 KiB
15_random.txt AC 6 ms 3800 KiB
16_random.txt AC 39 ms 7696 KiB
17_random.txt AC 4 ms 3604 KiB
18_random.txt AC 2 ms 3688 KiB
19_random.txt AC 15 ms 6772 KiB
20_random.txt AC 58 ms 7092 KiB
21_random.txt AC 3 ms 4284 KiB
22_random.txt AC 14 ms 4308 KiB
23_random.txt AC 6 ms 3728 KiB
24_max.txt AC 180 ms 8572 KiB
25_max.txt AC 180 ms 8724 KiB
26_max.txt AC 126 ms 8540 KiB
27_max.txt AC 129 ms 8540 KiB
28_zigzag.txt AC 153 ms 8628 KiB
29_zigzag.txt AC 145 ms 8596 KiB