#include "wombats.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const unsigned int maxn=5000+10,maxm=100+10;
unsigned int allr[maxn][maxm],allc[maxn][maxm],dp[maxn][maxm],n,m,ps[maxm],suf[maxm],psmx[maxn],sufmx[maxn];
void calc(){
for(unsigned int k=1;k<=m;k++){
for(unsigned int j=1;j<=m;j++){
ps[j]=ps[j-1]+allr[n][j-1];
}
for(unsigned int j=m;j>=1;j--){
suf[j]=suf[j+1]+allr[n][j];
}
for(unsigned int j=1;j<=m;j++){
if(j<=k){
dp[j][k]=ps[k]-ps[j];
}else{
dp[j][k]=suf[k]-suf[j];
}
}
// for(unsigned int j=1;j<=m;j++){
// cout<<dp[j][k]<<" ";
// }
// cout<<endl;
psmx[0]=sufmx[m+1]=inf;
for(unsigned int i=n-1;i>=1;i--){
for(unsigned int j=1;j<=m;j++){
ps[j]=ps[j-1]+allr[i][j-1];
}
for(unsigned int j=m;j>=1;j--){
suf[j]=suf[j+1]+allr[i][j];
}
for(unsigned int j=1;j<=m;j++){
psmx[j]=min(psmx[j-1],suf[j]+dp[j][k]+allc[i][j]);
}
for(unsigned int j=m;j>=1;j--){
sufmx[j]=min(sufmx[j+1],ps[j]+dp[j][k]+allc[i][j]);
}
for(unsigned int j=1;j<=m;j++){
// cout<<psmx[j-1]<<" "<<suf[j]<<" "<<sufmx[j+1]<<" "<<ps[j]<<endl;
dp[j][k]=min(dp[j][k]+allc[i][j],min(psmx[j-1]-suf[j],sufmx[j+1]-ps[j]));
}
// cout<<"salam"<<endl;
// for(unsigned int j=1;j<=m;j++){
// cout<<dp[j][k]<<" ";
// }
// cout<<endl;
}
}
}
void init( int R, int C, int H[5000][200], int V[5000][200]) {
n=R;
m=C;
for(unsigned int i=1;i<=n;i++){
for(unsigned int j=1;j<=m-1;j++){
allr[i][j]=H[i-1][j-1];
}
}
for(unsigned int i=1;i<=n-1;i++){
for(unsigned int j=1;j<=m;j++){
allc[i][j]=V[i-1][j-1];
}
}
calc();
}
void changeH( int P, int Q, int W) {
P++;
Q++;
allr[P][Q]=W;
calc();
}
void changeV( int P, int Q, int W) {
P++;
Q++;
allc[P][Q]=W;
calc();
}
int escape( int V1, int V2) {
V1++;
V2++;
return dp[V1][V2];
}
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;
| ^~~
wombats.cpp: In function 'void calc()':
wombats.cpp:28:28: error: 'inf' was not declared in this scope; did you mean 'ynf'?
28 | psmx[0]=sufmx[m+1]=inf;
| ^~~
| ynf