#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10,maxm=200+10,t=200,mt=(maxn/t)+5;
int n,m,inf=1e9+5;
struct bakhsh{
int allr[t+5][maxm],allc[t+5][maxm],dp[maxm][maxm],ps[maxm],suf[maxm],mxr=0;
void calps(int i){
for(int j=1;j<=m;j++){
ps[j]=ps[j-1]+allr[i][j-1];
}
}
void calc(){
for(int k=1;k<=m;k++){
calps(0);
for(int j=1;j<=m;j++){
dp[k][j]=abs(ps[k]-ps[j]);
}
for(int i=1;i<=mxr;i++){
int mn=inf;
for(int j=1;j<=m;j++){
mn=min(mn+allr[i][j-1],dp[k][j]+allc[i-1][j]);
ps[j]=mn;
}
mn=inf;
for(int j=m;j>=1;j--){
mn=min(mn+allr[i][j],dp[k][j]+allc[i-1][j]);
dp[k][j]=min(ps[j],mn);
}
}
for(int j=1;j<=m;j++){
dp[k][j]+=allc[mxr][j];
}
}
}
void updr(int i,int j,int w){
j++;
mxr=max(mxr,i);
allr[i][j]=w;
}
void updc(int i,int j,int w){
j++;
mxr=max(mxr,i);
allc[i][j]=w;
}
}allsq[mt];
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-1;j++){
allsq[i/t].updr(i%t,j,H[i][j]);
}
}
for(int i=0;i<n-1;i++){
for(int j=0;j<m;j++){
allsq[i/t].updc(i%t,j,V[i][j]);
}
}
for(int i=0;i<mt;i++){
allsq[i].calc();
}
}
void changeH( int P, int Q, int W) {
allsq[P/t].updr(P%t,Q,W);
allsq[P/t].calc();
}
void changeV( int P, int Q, int W) {
allsq[P/t].updc(P%t,Q,W);
allsq[P/t].calc();
}
int escape( int V1, int V2) {
V1++;
V2++;
return allsq[0].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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8792 KB |
Output is correct |
2 |
Incorrect |
5 ms |
8796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
47 ms |
3524 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
3596 KB |
Output is correct |
2 |
Correct |
214 ms |
3560 KB |
Output is correct |
3 |
Correct |
208 ms |
3596 KB |
Output is correct |
4 |
Correct |
210 ms |
3416 KB |
Output is correct |
5 |
Correct |
210 ms |
3576 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1041 ms |
3592 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
16900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
3420 KB |
Output is correct |
2 |
Correct |
204 ms |
3420 KB |
Output is correct |
3 |
Correct |
213 ms |
3420 KB |
Output is correct |
4 |
Correct |
209 ms |
3420 KB |
Output is correct |
5 |
Correct |
231 ms |
3580 KB |
Output is correct |
6 |
Incorrect |
8 ms |
16728 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
3592 KB |
Output is correct |
2 |
Correct |
207 ms |
3664 KB |
Output is correct |
3 |
Correct |
208 ms |
3600 KB |
Output is correct |
4 |
Correct |
214 ms |
3420 KB |
Output is correct |
5 |
Correct |
208 ms |
3664 KB |
Output is correct |
6 |
Incorrect |
9 ms |
16728 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |