Submission #645672

# Submission time Handle Problem Language Result Execution time Memory
645672 2022-09-27T15:53:17 Z notme Maxcomp (info1cup18_maxcomp) C++14
60 / 100
100 ms 16908 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e3;
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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 1360 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 1 ms 1232 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 1360 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 1232 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Runtime error 100 ms 16908 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -