Submission #10106

#TimeUsernameProblemLanguageResultExecution timeMemory
10106gs14004On grid (kriii2_O)C++98
0 / 4
0 ms2504 KiB
#include <cstdio> #include <algorithm> #include <deque> using namespace std; int a[301][301]; int sum[301][301]; int dp[301][301]; int r,c; int sliding[301][301]; void prep(){ scanf("%d %d",&r,&c); for (int i=1; i<=r; i++) { for (int j=1; j<=c; j++) { scanf("%d",&a[i][j]); } } for (int i=1; i<=r; i++) { for (int j=1; j<=c; j++) { sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j]; } } } int main(){ for (int i=0; i<301; i++) { for (int j=0; j<301; j++) { sliding[i][j] = -1e9; } } prep(); for (int j=1; j<=c; j++) { for (int i=1; i<=r; i++) { for (int k=1; k<i; k++) { int t = sliding[k][i]-sum[k][j]; dp[i][j] = max(dp[i][j],t); } dp[i][j] += 2*sum[i][j]; for (int k=i+1; k<=r; k++) { sliding[i][k] = max(sliding[i][k],dp[i][j]-sum[k][j]); } } } printf("%d",dp[r][c]-sum[r][c]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...