#include "wombats.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXR = 5000 + 10;
const int MAXC = 100 + 10;
const int INF = 2e9;
int r, c;
int costLeft[MAXR][MAXC];
int costDown[MAXR][MAXC];
int dp[MAXC][MAXR][MAXC];
int prefix[MAXR];
int suffix[MAXR];
void calcDP()
{
for (int end = 1 ; end <= c ; ++end)
{
int sum = 0;
dp[end][r][end] = 0;
for (int col = end - 1 ; col >= 1 ; col--)
{
sum += costLeft[r][col];
dp[end][r][col] = sum;
}
for (int col = end + 1 ; col <= c ; col++)
{
sum += costLeft[r][col - 1];
dp[end][r][col] = sum;
}
for (int row = r - 1 ; row >= 1 ; --row)
{
prefix[0] = suffix[c + 1] = INF;
for (int col = 1 ; col <= c ; ++col)
{
prefix[col] = std::min(prefix[col - 1] + costLeft[row][col - 1], dp[end][row + 1][col] + costDown[row][col]);
}
for (int col = c ; col >= 1 ; --col)
{
suffix[col] = std::min(suffix[col + 1] + costLeft[row][col], dp[end][row + 1][col] + costDown[row][col]);
}
for (int col = 1 ; col <= c ; ++col)
{
dp[end][row][col] = std::min(prefix[col], suffix[col]);
}
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200])
{
r = R;
c = C;
for (int i = 1 ; i <= r ; ++i)
{
for (int j = 1 ; j < c ; ++j)
{
costLeft[i][j] = H[i - 1][j - 1];
}
}
for (int i = 1 ; i < r ; ++i)
{
for (int j = 1 ; j <= c ; ++j)
{
costDown[i][j] = V[i - 1][j - 1];
}
}
calcDP();
}
void changeH(int P, int Q, int W)
{
costLeft[P + 1][Q + 1] = W;
calcDP();
}
void changeV(int P, int Q, int W)
{
costDown[P + 1][Q + 1] = W;
calcDP();
}
int escape(int V1, int V2)
{
V1++;
V2++;
return dp[V2][1][V1];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
8532 KB |
Output is correct |
2 |
Correct |
22 ms |
8532 KB |
Output is correct |
3 |
Correct |
76 ms |
10024 KB |
Output is correct |
4 |
Correct |
22 ms |
8532 KB |
Output is correct |
5 |
Correct |
22 ms |
8552 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
536 ms |
5644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16760 KB |
Output is correct |
2 |
Correct |
69 ms |
16756 KB |
Output is correct |
3 |
Correct |
56 ms |
16752 KB |
Output is correct |
4 |
Correct |
89 ms |
17508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
545 ms |
5632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
537 ms |
5636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |