Submission #67867006
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
vector<pair<int, int>> dirsFuture = {{1, 0}, {0, 1}};
vector<pair<int, int>> dirsPast = {{-1, 0}, {0, -1}};
bool check(int x, int y, int n, int m) {
if(x < 0 || y < 0 || x >= n || y >= m)
return false;
return true;
}
void solve() {
ll h, w;
cin >> h >> w;
vector<vector<ll>> arr(h, vector<ll> (w));
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
cin >> arr[i][j];
}
}
vector<ll> price(h + w - 1);
for(int i = 0; i < h + w - 1; i++) {
cin >> price[i];
}
price.begin(), price.end();
vector<vector<ll>> dp(h, vector<ll> (w, -1e12));
vector<vector<int>> vis(h, vector<int> (w, 0));
vector<vector<pair<int, int>>> par(h, vector<pair<int, int>> (w, {-1, -1}));
queue<pair<ll, pair<ll, ll>>> q;
q.push({0, {0, 0}});
while(!q.empty()) {
auto node = q.front(); q.pop();
ll idx = node.first;
ll x = node.second.first;
ll y = node.second.second;
// cout << x << " " << y << ": " << dp[x][y] << " --> ";
if(vis[x][y] == 1)
continue;
vis[x][y] = 1;
if(x == 0 && y == 0) {
dp[x][y] = arr[x][y] - price[idx];
}
else {
for(auto dir : dirsPast) {
int nx = x + dir.first;
int ny = y + dir.second;
if(check(nx, ny, h, w)) {
if(dp[x][y] < dp[nx][ny]) {
dp[x][y] = dp[nx][ny];
par[x][y] = {nx, ny};
}
}
}
dp[x][y] += arr[x][y] - price[idx];
}
for(auto dir : dirsFuture) {
int nx = x + dir.first;
int ny = y + dir.second;
if(check(nx, ny, h, w)) {
q.push({idx + 1, {nx, ny}});
}
}
}
// for(auto x : dp) {
// for(auto y : x) {
// cout << y << " ";
// }
// cout << '\n';
// }
// cout << '\n';
// cout << dp[h - 1][w - 1] << '\n';
pair<int, int> curr = {h - 1, w - 1};
ll ans = 0;
while(curr != make_pair(-1, -1)) {
ans = min(ans, dp[curr.first][curr.second]);
curr = par[curr.first][curr.second];
}
cout << abs(ans) << '\n';
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
for(int i = 0; i < t; i++) {
solve();
}
}
Submission Info
Submission Time
2025-07-24 16:43:11+0900
Task
E - Hungry Takahashi
User
AI_SAR
Language
C++ 20 (gcc 12.2)
Score
0
Code Size
2316 Byte
Status
WA
Exec Time
138 ms
Memory
48648 KiB
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:33:20: warning: ignoring return value of ‘constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::begin() [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator]’, declared with attribute ‘nodiscard’ [-Wunused-result]
33 | price.begin(), price.end();
| ~~~~~~~~~~~^~
In file included from /usr/include/c++/12/vector:64,
from /usr/include/c++/12/functional:62,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:71,
from Main.cpp:1:
/usr/include/c++/12/bits/stl_vector.h:868:7: note: declared here
868 | begin() _GLIBCXX_NOEXCEPT
| ^~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 450
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
2 ms
3456 KiB
00_sample_01.txt
AC
1 ms
3476 KiB
00_sample_02.txt
AC
1 ms
3548 KiB
01_random_00.txt
AC
105 ms
13164 KiB
01_random_01.txt
AC
91 ms
13128 KiB
01_random_02.txt
WA
90 ms
13192 KiB
01_random_03.txt
AC
76 ms
13272 KiB
01_random_04.txt
WA
60 ms
9116 KiB
01_random_05.txt
AC
59 ms
9024 KiB
01_random_06.txt
WA
46 ms
8996 KiB
01_random_07.txt
AC
44 ms
8984 KiB
01_random_08.txt
WA
61 ms
8576 KiB
01_random_09.txt
AC
61 ms
8688 KiB
01_random_10.txt
AC
46 ms
8600 KiB
01_random_11.txt
AC
47 ms
8576 KiB
01_random_12.txt
AC
59 ms
9220 KiB
01_random_13.txt
AC
59 ms
9096 KiB
01_random_14.txt
AC
45 ms
9100 KiB
01_random_15.txt
WA
45 ms
9104 KiB
01_random_16.txt
WA
60 ms
10152 KiB
01_random_17.txt
AC
60 ms
10208 KiB
01_random_18.txt
WA
46 ms
10140 KiB
01_random_19.txt
WA
45 ms
10204 KiB
01_random_20.txt
WA
95 ms
25772 KiB
01_random_21.txt
AC
89 ms
25800 KiB
01_random_22.txt
WA
80 ms
25768 KiB
01_random_23.txt
AC
73 ms
25944 KiB
01_random_24.txt
AC
138 ms
48440 KiB
01_random_25.txt
AC
123 ms
48488 KiB
01_random_26.txt
WA
123 ms
48440 KiB
01_random_27.txt
AC
108 ms
48648 KiB
02_random2_00.txt
AC
30 ms
8940 KiB
02_random2_01.txt
AC
36 ms
9060 KiB
02_random2_02.txt
AC
43 ms
9152 KiB
02_random2_03.txt
AC
61 ms
9172 KiB
02_random2_04.txt
AC
61 ms
9100 KiB
02_random2_05.txt
AC
62 ms
9080 KiB
03_handmade_00.txt
AC
1 ms
3604 KiB
03_handmade_01.txt
AC
1 ms
3460 KiB
03_handmade_02.txt
AC
1 ms
3444 KiB
03_handmade_03.txt
AC
28 ms
8900 KiB
03_handmade_04.txt
AC
65 ms
9012 KiB
03_handmade_05.txt
AC
63 ms
9168 KiB
03_handmade_06.txt
WA
77 ms
13220 KiB
03_handmade_07.txt
AC
78 ms
13224 KiB
03_handmade_08.txt
AC
114 ms
13232 KiB