답안 #780798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780798 2023-07-12T13:15:54 Z Andrey Maxcomp (info1cup18_maxcomp) C++14
100 / 100
99 ms 20640 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,a,b,ans = 0;
    cin >> n >> m;
    int haha[n][m];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> haha[i][j];
        }
    }
    pair<int,int> dp[n][m];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            dp[i][j] = {haha[i][j]+i+j,-haha[i][j]+i+j};
            if(i > 0) {
                dp[i][j] = {max(dp[i][j].first,dp[i-1][j].first),max(dp[i][j].second,dp[i-1][j].second)};
            }
            if(j > 0) {
                dp[i][j] = {max(dp[i][j].first,dp[i][j-1].first),max(dp[i][j].second,dp[i][j-1].second)};
            }
            ans = max(ans,dp[i][j].first-haha[i][j]-i-j);
            ans = max(ans,dp[i][j].second+haha[i][j]-i-j);
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m/2; j++) {
            swap(haha[i][j],haha[i][m-j-1]);
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            dp[i][j] = {haha[i][j]+i+j,-haha[i][j]+i+j};
            if(i > 0) {
                dp[i][j] = {max(dp[i][j].first,dp[i-1][j].first),max(dp[i][j].second,dp[i-1][j].second)};
            }
            if(j > 0) {
                dp[i][j] = {max(dp[i][j].first,dp[i][j-1].first),max(dp[i][j].second,dp[i][j-1].second)};
            }
            ans = max(ans,dp[i][j].first-haha[i][j]-i-j);
            ans = max(ans,dp[i][j].second+haha[i][j]-i-j);
        }
    }
    cout << ans-1;
    return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:9:13: warning: unused variable 'a' [-Wunused-variable]
    9 |     int n,m,a,b,ans = 0;
      |             ^
maxcomp.cpp:9:15: warning: unused variable 'b' [-Wunused-variable]
    9 |     int n,m,a,b,ans = 0;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 89 ms 18016 KB Output is correct
19 Correct 86 ms 20472 KB Output is correct
20 Correct 83 ms 19620 KB Output is correct
21 Correct 85 ms 20460 KB Output is correct
22 Correct 99 ms 20460 KB Output is correct
23 Correct 96 ms 20464 KB Output is correct
24 Correct 84 ms 20640 KB Output is correct