#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const unsigned int maxn=5000+10,maxm=200+10;
unsigned int allr[maxn][maxm],allc[maxn][maxm],dp[maxn][maxm],n,m,ps[maxm],suf[maxm],psmx[maxn],sufmx[maxn],inf=1e9+5;
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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
8280 KB |
Output is correct |
2 |
Correct |
20 ms |
8284 KB |
Output is correct |
3 |
Correct |
54 ms |
11152 KB |
Output is correct |
4 |
Correct |
20 ms |
8280 KB |
Output is correct |
5 |
Correct |
20 ms |
8284 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
37 ms |
2696 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
626 ms |
860 KB |
Output is correct |
2 |
Correct |
600 ms |
928 KB |
Output is correct |
3 |
Correct |
597 ms |
956 KB |
Output is correct |
4 |
Correct |
563 ms |
860 KB |
Output is correct |
5 |
Correct |
583 ms |
960 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2864 ms |
960 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
16560 KB |
Output is correct |
2 |
Correct |
85 ms |
16548 KB |
Output is correct |
3 |
Correct |
81 ms |
16560 KB |
Output is correct |
4 |
Correct |
103 ms |
17836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
629 ms |
932 KB |
Output is correct |
2 |
Correct |
627 ms |
860 KB |
Output is correct |
3 |
Correct |
641 ms |
944 KB |
Output is correct |
4 |
Correct |
606 ms |
964 KB |
Output is correct |
5 |
Correct |
629 ms |
856 KB |
Output is correct |
6 |
Correct |
81 ms |
16472 KB |
Output is correct |
7 |
Correct |
82 ms |
16476 KB |
Output is correct |
8 |
Correct |
85 ms |
16472 KB |
Output is correct |
9 |
Correct |
104 ms |
17748 KB |
Output is correct |
10 |
Correct |
20 ms |
8280 KB |
Output is correct |
11 |
Correct |
20 ms |
8284 KB |
Output is correct |
12 |
Correct |
56 ms |
11092 KB |
Output is correct |
13 |
Correct |
20 ms |
8280 KB |
Output is correct |
14 |
Correct |
19 ms |
8280 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
568 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
34 ms |
2884 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
3004 ms |
960 KB |
Output is correct |
28 |
Execution timed out |
20042 ms |
20140 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
599 ms |
856 KB |
Output is correct |
2 |
Correct |
559 ms |
928 KB |
Output is correct |
3 |
Correct |
630 ms |
860 KB |
Output is correct |
4 |
Correct |
603 ms |
1108 KB |
Output is correct |
5 |
Correct |
578 ms |
856 KB |
Output is correct |
6 |
Correct |
84 ms |
16556 KB |
Output is correct |
7 |
Correct |
83 ms |
16472 KB |
Output is correct |
8 |
Correct |
81 ms |
16472 KB |
Output is correct |
9 |
Correct |
100 ms |
17748 KB |
Output is correct |
10 |
Correct |
20 ms |
8508 KB |
Output is correct |
11 |
Correct |
20 ms |
8284 KB |
Output is correct |
12 |
Correct |
70 ms |
11156 KB |
Output is correct |
13 |
Correct |
20 ms |
8284 KB |
Output is correct |
14 |
Correct |
20 ms |
8284 KB |
Output is correct |
15 |
Correct |
6365 ms |
26384 KB |
Output is correct |
16 |
Execution timed out |
20057 ms |
24404 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |