답안 #1072073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072073 2024-08-23T14:01:51 Z LOLOLO Maxcomp (info1cup18_maxcomp) C++14
100 / 100
85 ms 17716 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           s     second
#define           f     first
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 1e3 + 10;
int a[N][N], mx[N][N];
int n, m;

int cal() {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            mx[i][j] = 2e9;
        }
    }

    int ans = -1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int v = a[i][j] - i - j;
            mx[i][j] = min({mx[i][j - 1], mx[i - 1][j], v});
            ans = max(ans, v - mx[i][j] - 1);   
        }
    }

    return ans;
}

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

    cin >> n >> m;

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

    int ans = cal();

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m / 2; j++) {
            swap(a[i][j], a[i][m - j + 1]);
        }
    }

    ans = max(ans, cal());

    for (int i = 1; i <= n / 2; i++) {
        for (int j = 1; j <= m; j++) {
            swap(a[i][j], a[n - i + 1][j]);
        }
    }

    ans = max(ans, cal());

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m / 2; j++) {
            swap(a[i][j], a[i][m - j + 1]);
        }
    }

    ans = max(ans, cal());
    cout << ans << '\n';
    return 0;
}

// a[x][y] - a[x1][y1] - (x - x1) - (y - y1)
// a[x][y] - a[x1][y1] - x + x1 - y + y1
// a[x][y] - x - y - (a[x1][y1] - x1 - y1)
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 78 ms 16704 KB Output is correct
19 Correct 78 ms 16724 KB Output is correct
20 Correct 74 ms 16448 KB Output is correct
21 Correct 85 ms 16712 KB Output is correct
22 Correct 72 ms 16688 KB Output is correct
23 Correct 78 ms 16724 KB Output is correct
24 Correct 70 ms 17716 KB Output is correct