답안 #645673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645673 2022-09-27T15:53:48 Z notme Maxcomp (info1cup18_maxcomp) C++14
100 / 100
145 ms 28620 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e3 + 10;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int n, m;
int a[MAXN][MAXN];

void read()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
            cin >> a[i][j];
    }
}
int maxx = -1;
int dp_ul[MAXN][MAXN];
void fill_dp_ul()
{
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            dp_ul[i][j] = a[i][j] + 1;
            if(j > 1)
            {
                dp_ul[i][j] = min(dp_ul[i][j], dp_ul[i][j-1] + 1);
                dp_ul[i][j] = min(dp_ul[i][j], a[i][j-1] + 2);
            }
            if(i > 1)
            {
                dp_ul[i][j] = min(dp_ul[i][j], dp_ul[i-1][j] + 1);
                dp_ul[i][j] = min(dp_ul[i][j], a[i-1][j] + 2);
            }
            maxx = max(maxx, a[i][j] - dp_ul[i][j]);
        }
    }
}
int dp_ur[MAXN][MAXN];
void fill_dp_ur()
{
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = m; j >= 1; -- j)
        {
            dp_ur[i][j] = a[i][j] + 1;
            if(j < m)
            {
                dp_ur[i][j] = min(dp_ur[i][j], dp_ur[i][j+1] + 1);
                dp_ur[i][j] = min(dp_ur[i][j], a[i][j+1] + 2);
            }
            if(i > 1)
            {
                dp_ur[i][j] = min(dp_ur[i][j], dp_ur[i-1][j] + 1);
                dp_ur[i][j] = min(dp_ur[i][j], a[i-1][j] + 2);
            }
            maxx = max(maxx, a[i][j] - dp_ur[i][j]);
        }
    }
}
int dp_dl[MAXN][MAXN];
void fill_dp_dl()
{
    for (int i = n; i >= 1; -- i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            dp_dl[i][j] = a[i][j] + 1;
            if(j > 1)
            {
                dp_dl[i][j] = min(dp_dl[i][j], dp_dl[i][j-1] + 1);
                dp_dl[i][j] = min(dp_dl[i][j], a[i][j-1] + 2);
            }
            if(i < n)
            {
                dp_dl[i][j] = min(dp_dl[i][j], dp_dl[i+1][j] + 1);
                dp_dl[i][j] = min(dp_dl[i][j], a[i+1][j] + 2);
            }
            maxx = max(maxx, a[i][j] - dp_dl[i][j]);
        }
    }
}
int dp_dr[MAXN][MAXN];
void fill_dp_dr()
{
    for (int i = n; i >= 1; -- i)
    {
        for (int j = m; j >= 1; -- j)
        {
            dp_dr[i][j] = a[i][j] + 1;
            if(j < m)
            {
                dp_dr[i][j] = min(dp_dr[i][j], dp_dr[i][j+1] + 1);
                dp_dr[i][j] = min(dp_dr[i][j], a[i][j+1] + 2);
            }
            if(i < n)
            {
                dp_dr[i][j] = min(dp_dr[i][j], dp_dr[i+1][j] + 1);
                dp_dr[i][j] = min(dp_dr[i][j], a[i+1][j] + 2);
            }
            maxx = max(maxx, a[i][j] - dp_dr[i][j]);
        }
    }
}
void solve()
{
    int ans = -1;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            for (int x = 1; x <= n; ++ x)
            {
                for (int y = 1; y <= m; ++ y)
                {

                    int maxx = max(a[i][j], a[x][y]);
                    int minn = min(a[i][j], a[x][y]);
                    int s = abs(x - i) + abs(y - j) + 1;
                    ///cout << i << " " << j << ", " << x << ", " << y << " -> " <<  maxx - minn - s << endl;
                    ans = max(ans, maxx - minn - s);
                }
            }
        }
    }
    cout << ans << endl;
}
int main()
{
    speed();

    read();
    fill_dp_ul();
    fill_dp_dl();
    fill_dp_ur();
    fill_dp_dr();
    cout << maxx << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 111 ms 19980 KB Output is correct
19 Correct 116 ms 28556 KB Output is correct
20 Correct 111 ms 28196 KB Output is correct
21 Correct 121 ms 28584 KB Output is correct
22 Correct 125 ms 28620 KB Output is correct
23 Correct 122 ms 28552 KB Output is correct
24 Correct 145 ms 28396 KB Output is correct