3 条题解
-
012322132131231 (褚战) LV 10 @ 2023-07-15 12:47:14
#include <queue> #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> using namespace std; #define Rep(i,_z,_zz) for(int i = (_z); i <= (_zz); i++) #define Red(i,_z,_zz) for(int i = (_z); i >= (_zz); i--) inline void read(int &x) { register char c; while((c=getchar()) < '0' || c > '9'); x = c-'0'; while((c=getchar()) >= '0' && c <= '9') x = x*10+c-'0'; } #define N 1510 int n,m,k,a[N][N],s[N][N],m1[N][N],m2[N][N],m3[N][N],m4[N][N],ans = 0; inline int Ma(int a,int b){return a>b?a:b;} void out(int k[N][N]) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) printf("%3d",k[i][j]<0?-1:k[i][j]); cout << "\n"; } } int main() { //freopen("large-4.in","r",stdin); //freopen("oil.out","w",stdout); read(n); read(m); read(k); memset(m1,-127/3,sizeof m1); memset(m2,-127/3,sizeof m2); memset(m3,-127/3,sizeof m3); memset(m4,-127/3,sizeof m4); memset(s,-127/3,sizeof s); Rep(i,1,n) Rep(j,1,m) read(a[i][j]),a[i][j] += (a[i-1][j]+a[i][j-1]-a[i-1][j-1]); Rep(i,k,n) Rep(j,k,m) s[i][j] = a[i][j]-a[i-k][j]-a[i][j-k]+a[i-k][j-k]; Rep(i,k,n) Rep(j,k,m) m1[i][j] = Ma(s[i][j],Ma(m1[i-1][j],m1[i][j-1])); Rep(i,k,n) Red(j,m-k+1,1) m2[i][j] = Ma(s[i][j+k-1],Ma(m2[i-1][j],m2[i][j+1])); Red(i,n-k+1,1) Rep(j,k,m) m3[i][j] = Ma(s[i+k-1][j],Ma(m3[i+1][j],m3[i][j-1])); Red(i,n-k+1,1) Red(j,m-k+1,1) m4[i][j] = Ma(s[i+k-1][j+k-1],Ma(m4[i+1][j],m4[i][j+1])); //out(m1); Rep(i,k,n-k+1) Rep(j,k,m-k+1) { ans = Ma(ans,m1[i][j]+m2[i][j+1]+m3[i+1][m]); ans = Ma(ans,m3[i][j]+m4[i][j+1]+m1[i-1][m]); ans = Ma(ans,m1[i][j]+m3[i+1][j]+m2[n][j+1]); ans = Ma(ans,m2[i][j]+m4[i+1][j]+m1[n][j-1]); ans = Ma(ans,s[i][j]+m1[n][j-k]+m2[n][j+1]); ans = Ma(ans,s[i][j]+m1[i-k][m]+m3[i+1][m]); } printf("%d",ans); // while(1); return 0; }
-
-12017-10-09 19:00:54@
#include <queue> #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> using namespace std; #define Rep(i,_z,_zz) for(int i = (_z); i <= (_zz); i++) #define Red(i,_z,_zz) for(int i = (_z); i >= (_zz); i--) inline void read(int &x) { register char c; while((c=getchar()) < '0' || c > '9'); x = c-'0'; while((c=getchar()) >= '0' && c <= '9') x = x*10+c-'0'; } #define N 1510 int n,m,k,a[N][N],s[N][N],m1[N][N],m2[N][N],m3[N][N],m4[N][N],ans = 0; inline int Ma(int a,int b){return a>b?a:b;} void out(int k[N][N]) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) printf("%3d",k[i][j]<0?-1:k[i][j]); cout << "\n"; } } int main() { //freopen("large-4.in","r",stdin); //freopen("oil.out","w",stdout); read(n); read(m); read(k); memset(m1,-127/3,sizeof m1); memset(m2,-127/3,sizeof m2); memset(m3,-127/3,sizeof m3); memset(m4,-127/3,sizeof m4); memset(s,-127/3,sizeof s); Rep(i,1,n) Rep(j,1,m) read(a[i][j]),a[i][j] += (a[i-1][j]+a[i][j-1]-a[i-1][j-1]); Rep(i,k,n) Rep(j,k,m) s[i][j] = a[i][j]-a[i-k][j]-a[i][j-k]+a[i-k][j-k]; Rep(i,k,n) Rep(j,k,m) m1[i][j] = Ma(s[i][j],Ma(m1[i-1][j],m1[i][j-1])); Rep(i,k,n) Red(j,m-k+1,1) m2[i][j] = Ma(s[i][j+k-1],Ma(m2[i-1][j],m2[i][j+1])); Red(i,n-k+1,1) Rep(j,k,m) m3[i][j] = Ma(s[i+k-1][j],Ma(m3[i+1][j],m3[i][j-1])); Red(i,n-k+1,1) Red(j,m-k+1,1) m4[i][j] = Ma(s[i+k-1][j+k-1],Ma(m4[i+1][j],m4[i][j+1])); //out(m1); Rep(i,k,n-k+1) Rep(j,k,m-k+1) { ans = Ma(ans,m1[i][j]+m2[i][j+1]+m3[i+1][m]); ans = Ma(ans,m3[i][j]+m4[i][j+1]+m1[i-1][m]); ans = Ma(ans,m1[i][j]+m3[i+1][j]+m2[n][j+1]); ans = Ma(ans,m2[i][j]+m4[i+1][j]+m1[n][j-1]); ans = Ma(ans,s[i][j]+m1[n][j-k]+m2[n][j+1]); ans = Ma(ans,s[i][j]+m1[i-k][m]+m3[i+1][m]); } printf("%d",ans); // while(1); return 0; }
-
-12017-01-13 08:20:21@
uses math;
var
a,b,c,d,f:array [0..2505,0..2505] of longint;
n,m,k,i,j,ans:longint;
begin
read(n,m,k);
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
for i:=1 to n do
for j:=1 to m do a[i,j]:=a[i,j]+a[i,j-1];
for i:=1 to n do
for j:=1 to m do a[i,j]:=a[i,j]+a[i-1,j];
n:=n-k+1; m:=m-k+1;
for i:=1 to n do
for j:=1 to m do f[i,j]:=a[i+k-1,j+k-1]-a[i-1,j+k-1]-a[i+k-1,j-1]+a[i-1,j-1];
fillchar(a,sizeof(a),0);
for i:=1 to n do
for j:=1 to m do a[i,j]:=max(f[i,j],max(a[i,j-1],a[i-1,j]));
for i:=1 to n do
for j:=m downto 1 do b[i,j]:=max(f[i,j],max(b[i,j+1],b[i-1,j]));
for i:=n downto 1 do
for j:=1 to m do c[i,j]:=max(f[i,j],max(c[i,j-1],c[i+1,j]));
for i:=n downto 1 do
for j:=m downto 1 do d[i,j]:=max(f[i,j],max(d[i,j+1],d[i+1,j]));
ans:=0;
for i:=k+1 to n do
for j:=k+1 to m do ans:=max(ans,max(a[i-k,j-k]+b[i-k,j]+d[i,1],b[i-k,1]+c[i,j-k]+d[i,j]));
for i:=k+1 to n do
for j:=k+1 to m do ans:=max(ans,max(c[1,j-k]+b[i-k,j]+d[i,j],d[1,j]+a[i-k,j-k]+c[i,j-k]));
for i:=1 to n do
for j:=k+1 to m-k do ans:=max(ans,a[n,j-k]+f[i,j]+d[1,j+k]);
for i:=k+1 to n-k do
for j:=1 to m do ans:=max(ans,a[i-k,m]+f[i,j]+d[i+k,1]);
write(ans);
end.
- 1