This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~ Be Name Khoda ~ //
#include "wombats.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnC = 205;
const int maxnR = 5e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n, m;
int dp[2][maxnR][maxnC];
int v[maxnR][maxnC], h[maxnR][maxnC];
inline void build(){
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
dp[1][i][j] = inf;
for(int i = 0; i < m; i++)
dp[1][i][i] = 0;
for(int j = 0; j < n; j++) for(int x = 0; x < m; x++){
int mn = inf;
for(int i = 0; i < m; i++){
dp[j & 1][x][i] = min(mn, dp[(j + 1) & 1][x][i] + (j ? v[j - 1][i] : 0));
mn = dp[j & 1][x][i] + h[j][i];
}
mn = inf;
for(int i = m - 1; i >= 0; i--){
dp[j & 1][x][i] = min(mn, dp[j & 1][x][i]);
if(i)
mn = dp[j & 1][x][i] + h[j][i - 1];
//cout << "check " << j << ' ' << x << ' ' << i << ' ' << dp[j & 1][x][i] << ' ' << mn << endl;
}
}
}
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];
}
build();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
build();
}
void changeV(int P, int Q, int W) {
h[P][Q] = W;
build();
}
int escape(int v1, int v2){
return dp[(n - 1) & 1][v1][v2];
}
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... |