This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define MAX_N 1000
int a[MAX_N][MAX_N], maxSum[4][MAX_N][MAX_N];
int max( int a, int b ) {
return a > b ? a : b;
}
int main() {
int n, m, maxW, l, c;
scanf( "%d%d", &n, &m );
for ( l = 0; l < n; l++ ) {
for ( c = 0; c < m; c++ )
scanf( "%d", &a[l][c] );
}
for ( l = 0; l < n; l++ ) {
for ( c = 0; c < m; c++ ) {
maxSum[0][l][c] = l + c - a[l][c];
if ( l > 0 )
maxSum[0][l][c] = max( maxSum[0][l][c], maxSum[0][l - 1][c] );
if ( c > 0 )
maxSum[0][l][c] = max( maxSum[0][l][c], maxSum[0][l][c - 1] );
}
}
for ( l = 0; l < n; l++ ) {
for ( c = m - 1; c >= 0; c-- ) {
maxSum[1][l][c] = l - c - a[l][c];
if ( l > 0 )
maxSum[1][l][c] = max( maxSum[1][l][c], maxSum[1][l - 1][c] );
if ( c < m - 1 )
maxSum[1][l][c] = max( maxSum[1][l][c], maxSum[1][l][c + 1] );
}
}
for ( l = n - 1; l >= 0; l-- ) {
for ( c = 0; c < m; c++ ) {
maxSum[2][l][c] = -l + c - a[l][c];
if ( l < n - 1 )
maxSum[2][l][c] = max( maxSum[2][l][c], maxSum[2][l + 1][c] );
if ( c > 0 )
maxSum[2][l][c] = max( maxSum[2][l][c], maxSum[2][l][c - 1] );
}
}
for ( l = n - 1; l >= 0; l-- ) {
for ( c = m - 1; c >= 0; c-- ) {
maxSum[3][l][c] = -l - c - a[l][c];
if ( l < n - 1 )
maxSum[3][l][c] = max( maxSum[3][l][c], maxSum[3][l + 1][c] );
if ( c < m - 1 )
maxSum[3][l][c] = max( maxSum[3][l][c], maxSum[3][l][c + 1] );
}
}
maxW = -1;
for ( l = 0; l < n; l++ ) {
for ( c = 0; c < m; c++ ) {
maxW = max( maxW, a[l][c] - l - c - 1 + maxSum[0][l][c] );
maxW = max( maxW, a[l][c] - l + c - 1 + maxSum[1][l][c] );
maxW = max( maxW, a[l][c] + l - c - 1 + maxSum[2][l][c] );
maxW = max( maxW, a[l][c] + l + c - 1 + maxSum[3][l][c] );
}
}
printf( "%d", maxW );
return 0;
}
Compilation message (stderr)
maxcomp.c: In function 'main':
maxcomp.c:15:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf( "%d%d", &n, &m );
| ^~~~~~~~~~~~~~~~~~~~~~~
maxcomp.c:18:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf( "%d", &a[l][c] );
| ^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |