Submission #1117983

# Submission time Handle Problem Language Result Execution time Memory
1117983 2024-11-24T14:32:30 Z _callmelucian Maxcomp (info1cup18_maxcomp) C++14
100 / 100
80 ms 13384 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

int a[1010][1010], colPos[1010], colNeg[1010], n, m;

int solve() {
    int ans = 0;
    for (int j = 1; j <= m; j++) colPos[j] = colNeg[j] = INT_MIN;
    for (int i = 1; i <= n; i++) {
        int bestPos = INT_MIN, bestNeg = INT_MIN;
        for (int j = 1; j <= m; j++) {
            colPos[j] = max(colPos[j], a[i][j] + i + j);
            colNeg[j] = max(colNeg[j], -a[i][j] + i + j);
            bestPos = max(bestPos, colPos[j]);
            bestNeg = max(bestNeg, colNeg[j]);
            ans = max({ans, a[i][j] - i - j + bestNeg, bestPos - a[i][j] - i - j});
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) cin >> a[i][j];

    int save = solve();
    for (int i = 1; i <= n; i++) reverse(a[i] + 1, a[i] + 1 + m);
    cout << max(save, solve()) - 1;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 760 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 760 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 74 ms 12944 KB Output is correct
19 Correct 75 ms 12848 KB Output is correct
20 Correct 80 ms 12360 KB Output is correct
21 Correct 73 ms 12872 KB Output is correct
22 Correct 76 ms 12872 KB Output is correct
23 Correct 75 ms 12872 KB Output is correct
24 Correct 70 ms 13384 KB Output is correct