#include<bits/stdc++.h>
#include "wombats.h"
using namespace std;
const int bucket_sz=700;
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[207][207][2][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 c=1;c<=m;c++){
dp[buck][fin][to%2][c]=getsum(to,min(c,fin),max(c,fin)-1);
}
for(int r=to-1;r>=from;r--){
optl[1]=dp[buck][fin][1-r%2][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][1-r%2][c]+cols[c][r]);
}
optr[m]=dp[buck][fin][1-r%2][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][1-r%2][c]+cols[c][r]);
}
for(int c=1;c<=m;c++){
dp[buck][fin][r%2][c]=min(optl[c],optr[c]);
}
}
}
}
int dp2[207][2][207];
int dist(int buck,int from,int to){
return dp[buck][to][seg[buck].first%2][from];
}
void solve(){
for(int start=1;start<=m;start++){
for(int i=0;i<=n/bucket_sz;i++){
for(int c=1;c<=m;c++){
dp2[start][i%2][c]=inf;
if(i==0){
dp2[start][i%2][c]=dist(i,start,c);
continue;
}
for(int k=1;k<=m;k++){
dp2[start][i%2][c]=min(dp2[start][i%2][c],dist(i,k,c)+cols[k][seg[i-1].second]+dp2[start][1-i%2][k]);
}
}
}
}
}
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();
}
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,seg[bucket[P]].second);
solve();
}
void changeV(int P, int Q, int W){
P++; Q++;
cols[Q][P]=W;
if(bucket[Q]==bucket[Q+1]){
calcdp(bucket[Q],seg[bucket[Q]].first,seg[bucket[Q]].second);
}
for(int i=0;i<=n/bucket_sz;i++){
calcdp(i,seg[i].first,seg[i].second);
}
solve();
}
int escape(int V1, int V2) {
V1++; V2++;
return dp2[V1][(n/bucket_sz)%2][V2];
}
/*int main(){
init(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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12880 KB |
Output is correct |
2 |
Correct |
26 ms |
12932 KB |
Output is correct |
3 |
Correct |
50 ms |
14408 KB |
Output is correct |
4 |
Correct |
14 ms |
12880 KB |
Output is correct |
5 |
Correct |
14 ms |
12880 KB |
Output is correct |
6 |
Correct |
1 ms |
4600 KB |
Output is correct |
7 |
Correct |
1 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4432 KB |
Output is correct |
2 |
Correct |
1 ms |
4604 KB |
Output is correct |
3 |
Correct |
1 ms |
4600 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6480 KB |
Output is correct |
8 |
Correct |
1 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
6480 KB |
Output is correct |
11 |
Correct |
43 ms |
7496 KB |
Output is correct |
12 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
492 ms |
8784 KB |
Output is correct |
2 |
Correct |
659 ms |
8812 KB |
Output is correct |
3 |
Correct |
340 ms |
8784 KB |
Output is correct |
4 |
Correct |
687 ms |
8784 KB |
Output is correct |
5 |
Correct |
467 ms |
8784 KB |
Output is correct |
6 |
Correct |
1 ms |
4432 KB |
Output is correct |
7 |
Correct |
1 ms |
4536 KB |
Output is correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Correct |
2019 ms |
8800 KB |
Output is correct |
10 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
19036 KB |
Output is correct |
2 |
Correct |
57 ms |
19024 KB |
Output is correct |
3 |
Correct |
35 ms |
19024 KB |
Output is correct |
4 |
Correct |
59 ms |
19792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
486 ms |
8800 KB |
Output is correct |
2 |
Correct |
621 ms |
8804 KB |
Output is correct |
3 |
Correct |
332 ms |
8808 KB |
Output is correct |
4 |
Correct |
670 ms |
8804 KB |
Output is correct |
5 |
Correct |
470 ms |
8812 KB |
Output is correct |
6 |
Correct |
32 ms |
19024 KB |
Output is correct |
7 |
Correct |
56 ms |
19024 KB |
Output is correct |
8 |
Correct |
39 ms |
19028 KB |
Output is correct |
9 |
Correct |
54 ms |
19736 KB |
Output is correct |
10 |
Correct |
14 ms |
12880 KB |
Output is correct |
11 |
Correct |
14 ms |
12880 KB |
Output is correct |
12 |
Correct |
50 ms |
14316 KB |
Output is correct |
13 |
Correct |
14 ms |
12932 KB |
Output is correct |
14 |
Correct |
14 ms |
12880 KB |
Output is correct |
15 |
Correct |
1 ms |
4600 KB |
Output is correct |
16 |
Correct |
1 ms |
4432 KB |
Output is correct |
17 |
Correct |
1 ms |
4432 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
2 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6648 KB |
Output is correct |
21 |
Correct |
1 ms |
6480 KB |
Output is correct |
22 |
Correct |
1 ms |
6480 KB |
Output is correct |
23 |
Correct |
1 ms |
6480 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
43 ms |
7452 KB |
Output is correct |
26 |
Correct |
2 ms |
6480 KB |
Output is correct |
27 |
Correct |
2048 ms |
8808 KB |
Output is correct |
28 |
Execution timed out |
20053 ms |
21340 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
486 ms |
8804 KB |
Output is correct |
2 |
Correct |
682 ms |
8784 KB |
Output is correct |
3 |
Correct |
333 ms |
8784 KB |
Output is correct |
4 |
Correct |
661 ms |
8960 KB |
Output is correct |
5 |
Correct |
480 ms |
8784 KB |
Output is correct |
6 |
Correct |
33 ms |
19024 KB |
Output is correct |
7 |
Correct |
60 ms |
19024 KB |
Output is correct |
8 |
Correct |
34 ms |
19024 KB |
Output is correct |
9 |
Correct |
55 ms |
19784 KB |
Output is correct |
10 |
Correct |
15 ms |
12880 KB |
Output is correct |
11 |
Correct |
15 ms |
12880 KB |
Output is correct |
12 |
Correct |
56 ms |
14408 KB |
Output is correct |
13 |
Correct |
14 ms |
12880 KB |
Output is correct |
14 |
Correct |
14 ms |
12880 KB |
Output is correct |
15 |
Correct |
2685 ms |
22604 KB |
Output is correct |
16 |
Execution timed out |
20037 ms |
22556 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |