답안 #494708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494708 2021-12-16T03:10:10 Z dannyboy20031204 Maxcomp (info1cup18_maxcomp) C++17
100 / 100
132 ms 16948 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mp make_pair 
using namespace std;
void db() {cout << endl;}
template <typename T, typename ...U> void db(T a, U ...b) {
    //return;
    cout << a << ' ', db(b...);
}
#ifdef Cloud
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define file ios::sync_with_stdio(false); cin.tie(0)
#endif
const int N = 3001;
signed main(){
    file;
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    int mi[n][m], ans = -1;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (!i and !j) mi[i][j] = a[i][j] - i - j;
            else if (!i) mi[i][j] = min(mi[i][j - 1], a[i][j] - i - j);
            else if (!j) mi[i][j] = min(mi[i - 1][j], a[i][j] - i - j);
            else mi[i][j] = min({mi[i - 1][j], mi[i][j - 1], a[i][j] - i - j});
            ans = max(ans, a[i][j] - i - j - mi[i][j] - 1);
        }
    }
    //db(ans);
    for (int i = 0; i < n; i++){
        for (int j = m - 1; j >= 0; j--){
            if (!i and j == m - 1) mi[i][j] = a[i][j] - i + j;
            else if (!i) mi[i][j] = min(mi[i][j + 1], a[i][j] - i + j);
            else if (j == m - 1) mi[i][j] = min(mi[i - 1][j], a[i][j] - i + j);
            else mi[i][j] = min({mi[i - 1][j], mi[i][j + 1], a[i][j] - i + j});
            ans = max(ans, a[i][j] - i + j - mi[i][j] - 1);
        }
    }
    for (int i = n - 1; i >= 0; i--){
        for (int j = 0; j < m; j++){
            if (i == n - 1 and !j) mi[i][j] = a[i][j] + i - j;
            else if (i == n - 1) mi[i][j] = min(mi[i][j - 1], a[i][j] + i - j);
            else if (!j) mi[i][j] = min(mi[i + 1][j], a[i][j] + i - j);
            else mi[i][j] = min({mi[i + 1][j], mi[i][j - 1], a[i][j] + i - j});
            ans = max(ans, a[i][j] + i - j - mi[i][j] - 1);
        }
    }
    for (int i = n - 1; i >= 0; i--){
        for (int j = m - 1; j >= 0; j--){
            if (i == n - 1 and j == m - 1) mi[i][j] = a[i][j] + i + j;
            else if (i == n - 1) mi[i][j] = min(mi[i][j + 1], a[i][j] + i + j);
            else if (j == m - 1) mi[i][j] = min(mi[i + 1][j], a[i][j] + i + j);
            else mi[i][j] = min({mi[i + 1][j], mi[i][j + 1], a[i][j] + i + j});
            ans = max(ans, a[i][j] + i + j - mi[i][j] - 1);
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 122 ms 16732 KB Output is correct
19 Correct 114 ms 16660 KB Output is correct
20 Correct 120 ms 15908 KB Output is correct
21 Correct 119 ms 16612 KB Output is correct
22 Correct 131 ms 16604 KB Output is correct
23 Correct 118 ms 16596 KB Output is correct
24 Correct 132 ms 16948 KB Output is correct