#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;
int R, C;
int H[5000][200], V[5000][200], DP[5000][200];
void init(int r, int c, int h[5000][200], int v[5000][200])
{
R = r;
C = c;
for(int i = 0; i < R; i++)
{
for(int j = 0; j < C; j++) {H[i][j] = h[i][j]; V[i][j] = v[i][j];}
}
return;
}
void changeH(int r, int c, int w)
{
H[r][c] = w;
return;
}
void changeV(int r, int c, int w)
{
V[r][c] = w;
return;
}
int escape(int u, int v)
{
DP[0][u] = 0;
for(int i = u - 1; i >= 0; i--) DP[0][i] = DP[0][i + 1] + H[0][i];
if(u < (C - 1)) for(int i = u + 1; i < C; i++) DP[0][i] = DP[0][i - 1] + H[0][i - 1];
for(int i = 1; i < R; i++)
{
DP[i][0] = DP[i - 1][0] + V[i - 1][0];
for(int j = 1; j < C; j++)
{
DP[i][j] = min(DP[i][j - 1] + H[i][j - 1], DP[i - 1][j] + V[i - 1][j]);
}
int dp = DP[i - 1][C - 1] + V[i - 1][C - 1];
for(int j = C - 2; j >= 0; j--)
{
dp = min(dp + H[i][j], DP[i - 1][j] + V[i - 1][j]);
DP[i][j] = min(dp, DP[i][j]);
}
}
return DP[R - 1][v];
}
//int h[5000][200], v[5000][200];
//int main()
//{
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int r, c;
// cin >> r >> c;
// for(int i = 0; i < r; i++)
// {
// for(int j = 0; j < (c - 1); j++) cin >> h[i][j];
// }
// for(int i = 0; i < (r - 1); i++)
// {
// for(int j = 0; j < c; j++) cin >> v[i][j];
// }
// init(r, c, h, v);
// int Q, t, u, v, w;
// cin >> Q;
// while(Q--)
// {
// cin >> t >> u >> v;
// if(t == 3) cout << escape(u, v) << '\n';
// else
// {
// cin >> w;
// if(t == 1) changeH(u, v, w);
// else changeV(u, v, w);
// }
// }
// return 0;
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |