Submission #467045

#TimeUsernameProblemLanguageResultExecution timeMemory
467045LucaIlieMaxcomp (info1cup18_maxcomp)C11
100 / 100
173 ms28296 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...