답안 #467045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467045 2021-08-21T12:02:25 Z LucaIlie Maxcomp (info1cup18_maxcomp) C
100 / 100
173 ms 28296 KB
#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

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] );
      |             ^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 1228 KB Output is correct
10 Correct 1 ms 1192 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 2 ms 1196 KB Output is correct
13 Correct 1 ms 1228 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1192 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 2 ms 1196 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 166 ms 28248 KB Output is correct
19 Correct 173 ms 28268 KB Output is correct
20 Correct 160 ms 27916 KB Output is correct
21 Correct 167 ms 28296 KB Output is correct
22 Correct 166 ms 28272 KB Output is correct
23 Correct 166 ms 28228 KB Output is correct
24 Correct 162 ms 28228 KB Output is correct