Submission #22237607
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[1005][505];
ll D[1005][505];
ll dijk() {
rep(y, 0, H * 2) rep(x, 0, W) D[y][x] = infl;
rep(y, 0, H * 2) 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 (y < H) {
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 });
if (chmin(D[y + H][x], cst + 1)) que.push({ D[y + H][x], (y + H) * W + x });
}
else {
if (H < y) if (chmin(D[y - 1][x], cst + 1)) que.push({ D[y - 1][x], (y - 1) * W + x });
if (chmin(D[y - H][x], cst)) que.push({ D[y - H][x], (y - H) * 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
2021-05-01 23:08:31+0900
Task
E - Sneaking
User
hamayanhamayan
Language
C++ (GCC 9.2.1)
Score
500
Code Size
2986 Byte
Status
AC
Exec Time
163 ms
Memory
15264 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
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
1 ms
3644 KiB
02_sample.txt
AC
1 ms
3608 KiB
03_sample.txt
AC
2 ms
3644 KiB
04_random.txt
AC
4 ms
4352 KiB
05_random.txt
AC
19 ms
7600 KiB
06_random.txt
AC
13 ms
6356 KiB
07_random.txt
AC
2 ms
3676 KiB
08_random.txt
AC
2 ms
3796 KiB
09_random.txt
AC
6 ms
3840 KiB
10_random.txt
AC
2 ms
3884 KiB
11_random.txt
AC
23 ms
7212 KiB
12_random.txt
AC
8 ms
4176 KiB
13_random.txt
AC
72 ms
7884 KiB
14_random.txt
AC
8 ms
4800 KiB
15_random.txt
AC
6 ms
3940 KiB
16_random.txt
AC
36 ms
10008 KiB
17_random.txt
AC
3 ms
3692 KiB
18_random.txt
AC
2 ms
3696 KiB
19_random.txt
AC
11 ms
8720 KiB
20_random.txt
AC
63 ms
8996 KiB
21_random.txt
AC
3 ms
4784 KiB
22_random.txt
AC
16 ms
4692 KiB
23_random.txt
AC
2 ms
3816 KiB
24_max.txt
AC
163 ms
11652 KiB
25_max.txt
AC
158 ms
11596 KiB
26_max.txt
AC
68 ms
15264 KiB
27_max.txt
AC
88 ms
11512 KiB
28_zigzag.txt
AC
115 ms
11444 KiB
29_zigzag.txt
AC
115 ms
11472 KiB