This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wombats.h"
#include <bits/stdc++.h>
#define lli long long
using namespace std;
int n, m;
lli h[5002][201], v[5002][201];
lli dp[5002][201], pr[201];
void upd(int v1)
{
for(int i = 0; i < m; i++) dp[n - 1][i] = 1e17;
dp[n - 1][v1] = 0;
for(int i = n - 2; i >= 0; i--)
{
pr[0] = 0;
for(int j = 0; j < m - 1; j++)
pr[j + 1] = pr[j] + h[i + 1][j];
lli mn = dp[i + 1][0] + pr[m - 1];
for(int j = 0; j < m; j++)
{
mn = min(mn, dp[i + 1][j] + pr[m - 1] - pr[j]);
dp[i][j] = mn - (pr[m - 1] - pr[j]) + v[i][j];
}
mn = dp[i + 1][m - 1] + pr[m - 1];
for(int j = m - 1; j >= 0; j--)
{
mn = min(mn, dp[i + 1][j] + pr[j]);
dp[i][j] = min(dp[i][j], mn - pr[j] + v[i][j]);
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R; m = C;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) h[i][j] = H[i][j], v[i][j]= V[i][j];
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
}
int escape(int V1, int V2) {
upd(V2);
lli mn = dp[0][V1], sm = 0;
for(int i = V1; i < m - 1; i++)
{
sm += h[0][i];
mn = min(mn, dp[0][i + 1] + sm);
}
sm = 0;
for(int i = V1 - 1; i >= 0; i--)
{
sm += h[0][i];
mn = min(mn, dp[0][i] + sm);
}
return mn;
}
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# | 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... |