Submission #1095445

# Submission time Handle Problem Language Result Execution time Memory
1095445 2024-10-02T08:13:14 Z rahidilbayramli Maxcomp (info1cup18_maxcomp) C++17
100 / 100
96 ms 32660 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//random_device rd;
//mt19937 gen(rd());
//uniform_int_distribution<> d(0, 1e9);
void solve()
{
    ll n, m, i, j;
    cin >> n >> m;
    ll a[n+5][m+5];
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
            cin >> a[i][j];
    }
    ll minn[n+5][m+5], maxx[n+5][m+5];
    for(i = 0; i <= n; i++)
    {
        for(j = 0; j <= m; j++)
        {
            minn[i][j] = LLONG_MAX;
            maxx[i][j] = LLONG_MIN;
        }
    }
    ll res = -1;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
        {
            minn[i][j] = min(minn[i-1][j], minn[i][j-1]);
            maxx[i][j] = max(maxx[i-1][j], maxx[i][j-1]);
            minn[i][j] = min(minn[i][j], a[i][j] - i - j);
            maxx[i][j] = max(maxx[i][j], a[i][j] + i + j);
            res = max(res, maxx[i][j] - a[i][j] - i - j);
            res = max(res, a[i][j] - i - j - minn[i][j]);
        }
    }
    for(i = 1; i <= n; i++)
        reverse(a[i]+1, a[i]+m+1);
    for(i = 0; i <= n; i++)
    {
        for(j = 0; j <= m; j++)
        {
            minn[i][j] = LLONG_MAX;
            maxx[i][j] = LLONG_MIN;
        }
    }
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
        {
            minn[i][j] = min(minn[i-1][j], minn[i][j-1]);
            maxx[i][j] = max(maxx[i-1][j], maxx[i][j-1]);
            minn[i][j] = min(minn[i][j], a[i][j] - i - j);
            maxx[i][j] = max(maxx[i][j], a[i][j] + i + j);
            res = max(res, maxx[i][j] - a[i][j] - i - j);
            res = max(res, a[i][j] - i - j - minn[i][j]);
        }
    }
    cout << res-1 << "\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 95 ms 32660 KB Output is correct
19 Correct 79 ms 32592 KB Output is correct
20 Correct 83 ms 31060 KB Output is correct
21 Correct 82 ms 32596 KB Output is correct
22 Correct 87 ms 32596 KB Output is correct
23 Correct 88 ms 32524 KB Output is correct
24 Correct 96 ms 32080 KB Output is correct