#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "wombats.h"
using namespace std;
const int bucket_sz=207;
const int inf=1e9;
int n,m;
int rows[5007][207];
int cols[207][5007];
int bucket[5007];
pair<int,int> seg[5007];
int dp[26][207][210][207];
int optl[207],optr[207];
int getsum(int row,int l,int r){
return rows[row][r]-rows[row][l-1];
}
void calcdp(int buck,int from,int to){
for(int fin=1;fin<=m;fin++){
for(int r=to;r>=from;r--){
if(r==seg[buck].second){
for(int c=1;c<=m;c++){
dp[buck][fin][r-from][c]=getsum(r,min(c,fin),max(c,fin)-1);
}
continue;
}
optl[1]=dp[buck][fin][r+1-from][1]+cols[1][r];
for(int c=2;c<=m;c++){
optl[c]=min(optl[c-1]+getsum(r,c-1,c-1),dp[buck][fin][r+1-from][c]+cols[c][r]);
}
optr[m]=dp[buck][fin][r+1-from][m]+cols[m][r];
for(int c=m-1;c>=1;c--){
optr[c]=min(optr[c+1]+getsum(r,c,c),dp[buck][fin][r+1-from][c]+cols[c][r]);
}
for(int c=1;c<=m;c++){
dp[buck][fin][r-from][c]=min(optl[c],optr[c]);
}
}
}
}
int dp2[207][30][207];
int dist(int buck,int from,int to){
return dp[buck][to][0][from];
}
void optdp(int start,int buck,int l,int r,int optl,int optr){
if(l>r)return;
int mid=(l+r)/2;
int opt=optl;
dp2[start][buck][mid]=inf;
for(int i=optl;i<=optr;i++){
if(dp2[start][buck-1][i] + cols[i][seg[buck-1].second] + dist(buck,i,mid) < dp2[start][buck][mid]){
dp2[start][buck][mid]=dp2[start][buck-1][i] + cols[i][seg[buck-1].second] + dist(buck,i,mid);
opt=i;
}
}
optdp(start,buck,l,mid-1,optl,opt);
optdp(start,buck,mid+1,r,opt,optr);
}
void solve(int last){
for(int start=1;start<=m;start++){
for(int c=1;c<=m;c++){
dp2[start][0][c]=dist(0,start,c);
}
}
for(int start=1;start<=m;start++){
for(int i=last;i<=n/bucket_sz;i++){
optdp(start,i,1,m,1,m);
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
//void init(int R,int C,vector< vector<int> > H,vector< vector<int> > V){
n=R; m=C;
for(int i=1;i<=n;i++){
for(int f=1;f<=m-1;f++){
rows[i][f]=H[i-1][f-1];
rows[i][f]+=rows[i][f-1];
}
}
for(int i=1;i<=m;i++){
for(int f=1;f<=n-1;f++){
cols[i][f]=V[f-1][i-1];
}
}
for(int i=1;i<=n;i++){
bucket[i]=i/bucket_sz;
if(seg[bucket[i]].first==0)seg[bucket[i]].first=i;
seg[bucket[i]].second=i;
}
for(int i=0;i<=n/bucket_sz;i++){
calcdp(i,seg[i].first,seg[i].second);
}
solve(1);
}
void changeH(int P, int Q, int W) {
P++; Q++;
int dif=W-(rows[P][Q]-rows[P][Q-1]);
for(int i=Q;i<=m-1;i++){
rows[P][i]+=dif;
}
calcdp(bucket[P],seg[bucket[P]].first,P);
solve(max(bucket[P],1));
}
void changeV(int P, int Q, int W){
P++; Q++;
cols[Q][P]=W;
if(bucket[P]==bucket[P+1]){
calcdp(bucket[P],seg[bucket[P]].first,P);
}
solve(max(bucket[P],1));
}
int escape(int V1, int V2) {
V1++; V2++;
return dp2[V1][(n/bucket_sz)][V2];
}
/*int main(){
nit(4,1,{{}},{{1},{1},{1},{1}});
cout<<escape(0,0)<<"\n";
changeV(0,0,2);
cout<<escape(0,0)<<"\n";
changeV(1,0,2);
cout<<escape(0,0)<<"\n";
changeV(2,0,2);
cout<<escape(0,0)<<"\n";
init(3,4,{{0,2,5},{7,1,1},{0,4,0}},{{0,0,0,2},{0,3,4,7}});
cout<<escape(2,1)<<"\n";
cout<<escape(3,3)<<"\n";
changeV(0,0,5);
changeH(1,1,6);
cout<<escape(2,1)<<"\n";
return 0;
}*/
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 |
9 ms |
59984 KB |
Output is correct |
2 |
Correct |
7 ms |
59984 KB |
Output is correct |
3 |
Correct |
45 ms |
61600 KB |
Output is correct |
4 |
Correct |
7 ms |
59984 KB |
Output is correct |
5 |
Correct |
6 ms |
40864 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
2 ms |
6480 KB |
Output is correct |
8 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
2 ms |
10576 KB |
Output is correct |
9 |
Correct |
2 ms |
10576 KB |
Output is correct |
10 |
Correct |
2 ms |
10576 KB |
Output is correct |
11 |
Correct |
43 ms |
11496 KB |
Output is correct |
12 |
Correct |
2 ms |
10576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
306 ms |
29264 KB |
Output is correct |
2 |
Correct |
45 ms |
29264 KB |
Output is correct |
3 |
Correct |
169 ms |
29264 KB |
Output is correct |
4 |
Correct |
194 ms |
29344 KB |
Output is correct |
5 |
Correct |
49 ms |
29264 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
2 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
243 ms |
29264 KB |
Output is correct |
10 |
Correct |
2 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
74320 KB |
Output is correct |
2 |
Correct |
13 ms |
74320 KB |
Output is correct |
3 |
Correct |
13 ms |
74340 KB |
Output is correct |
4 |
Correct |
34 ms |
74992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
29324 KB |
Output is correct |
2 |
Correct |
44 ms |
29316 KB |
Output is correct |
3 |
Correct |
170 ms |
29328 KB |
Output is correct |
4 |
Correct |
206 ms |
29300 KB |
Output is correct |
5 |
Correct |
48 ms |
29264 KB |
Output is correct |
6 |
Correct |
11 ms |
74400 KB |
Output is correct |
7 |
Correct |
12 ms |
74320 KB |
Output is correct |
8 |
Correct |
12 ms |
74424 KB |
Output is correct |
9 |
Correct |
31 ms |
75056 KB |
Output is correct |
10 |
Correct |
7 ms |
60140 KB |
Output is correct |
11 |
Correct |
8 ms |
59984 KB |
Output is correct |
12 |
Correct |
56 ms |
61512 KB |
Output is correct |
13 |
Correct |
7 ms |
59984 KB |
Output is correct |
14 |
Correct |
6 ms |
59984 KB |
Output is correct |
15 |
Correct |
2 ms |
6480 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
1 ms |
6656 KB |
Output is correct |
18 |
Correct |
2 ms |
10576 KB |
Output is correct |
19 |
Correct |
2 ms |
10576 KB |
Output is correct |
20 |
Correct |
2 ms |
10576 KB |
Output is correct |
21 |
Correct |
2 ms |
10692 KB |
Output is correct |
22 |
Correct |
2 ms |
10576 KB |
Output is correct |
23 |
Correct |
2 ms |
10576 KB |
Output is correct |
24 |
Correct |
2 ms |
10744 KB |
Output is correct |
25 |
Correct |
46 ms |
11588 KB |
Output is correct |
26 |
Correct |
2 ms |
10576 KB |
Output is correct |
27 |
Correct |
239 ms |
29328 KB |
Output is correct |
28 |
Runtime error |
220 ms |
262144 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
29320 KB |
Output is correct |
2 |
Correct |
46 ms |
29324 KB |
Output is correct |
3 |
Correct |
166 ms |
29324 KB |
Output is correct |
4 |
Correct |
197 ms |
29292 KB |
Output is correct |
5 |
Correct |
49 ms |
29264 KB |
Output is correct |
6 |
Correct |
14 ms |
74448 KB |
Output is correct |
7 |
Correct |
12 ms |
74320 KB |
Output is correct |
8 |
Correct |
16 ms |
74444 KB |
Output is correct |
9 |
Correct |
36 ms |
75108 KB |
Output is correct |
10 |
Correct |
8 ms |
59984 KB |
Output is correct |
11 |
Correct |
7 ms |
59984 KB |
Output is correct |
12 |
Correct |
46 ms |
61492 KB |
Output is correct |
13 |
Correct |
7 ms |
60112 KB |
Output is correct |
14 |
Correct |
8 ms |
59984 KB |
Output is correct |
15 |
Runtime error |
436 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |