답안 #916885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916885 2024-01-26T17:06:15 Z andrei_iorgulescu Maxcomp (info1cup18_maxcomp) C++14
100 / 100
91 ms 21316 KB
#include <bits/stdc++.h>

using namespace std;

int n,m,a[1005][1005];
int bestmic[1005][1005],bestmare[1005][1005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            bestmare[i][j] = bestmic[i][j] = -1e9;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        int mx = -1e9;
        int mn = -2e9;
        for (int j = 1; j <= m; j++)
        {
            mx = max(mx,a[i][j] + j);
            mn = max(mn,-a[i][j] + j);
            bestmare[i][j] = max(bestmare[i][j],mx - j);
            bestmic[i][j] = max(bestmic[i][j],mn - j);
        }
        mx = -1e9;
        mn = -2e9;
        for (int j = m; j >= 1; j--)
        {
            mx = max(mx,a[i][j] - j);
            mn = max(mn,-a[i][j] - j);
            bestmare[i][j] = max(bestmare[i][j],mx + j);
            bestmic[i][j] = max(bestmic[i][j],mn + j);
        }
    }
    for (int j = 1; j <= m; j++)
    {
        int mx = -1e9;
        int mn = -2e9;
        for (int i = 1; i <= n; i++)
        {
            mx = max(mx,a[i][j] + i);
            mn = max(mn,-a[i][j] + i);
            bestmare[i][j] = max(bestmare[i][j],mx - i);
            bestmic[i][j] = max(bestmic[i][j],mn - i);
        }
        mx = -1e9;
        mn = -2e9;
        for (int i = n; i >= 1; i--)
        {
            mx = max(mx,a[i][j] - i);
            mn = max(mn,-a[i][j] - i);
            bestmare[i][j] = max(bestmare[i][j],mx + i);
            bestmic[i][j] = max(bestmic[i][j],mn + i);
        }
    }
    /*for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cout << bestmare[i][j] << ' ';
        cout << '\n';
    }
    cout << '\n';
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cout << bestmic[i][j] << ' ';
        cout << '\n';
    }*/
    int ans = -1e9;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            ans = max(ans,bestmare[i][j] + bestmic[i][j] - 1);
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6616 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4564 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6616 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 88 ms 20660 KB Output is correct
19 Correct 91 ms 20680 KB Output is correct
20 Correct 78 ms 20268 KB Output is correct
21 Correct 88 ms 20564 KB Output is correct
22 Correct 83 ms 20788 KB Output is correct
23 Correct 85 ms 20816 KB Output is correct
24 Correct 84 ms 21316 KB Output is correct