Submission #687298

# Submission time Handle Problem Language Result Execution time Memory
687298 2023-01-26T09:20:34 Z alexdd Maxcomp (info1cup18_maxcomp) C++17
100 / 100
177 ms 32440 KB
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int long long
const long long INF = 10000000000007;
int n,m;
int mat[1001][1001];
long long aint[4100][2];///aint[0] = stanga sus   val - lin - col
                        ///aint[1] = dreapta sus
void upd(int nod, int st, int dr, int poz, long long newv, int dim)
{
    if(st==dr)
    {
        aint[nod][dim] = max(aint[nod][dim], newv);
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij)
        upd(nod*2,st,mij,poz,newv,dim);
    else
        upd(nod*2+1,mij+1,dr,poz,newv,dim);
    aint[nod][dim] = max(aint[nod*2][dim], aint[nod*2+1][dim]);
}
long long qry(int nod, int st, int dr, int le, int ri, int dim)
{
    if(le>ri)
        return -INF;
    if(le==st && dr==ri)
        return aint[nod][dim];
    int mij=(st+dr)/2;
    return max(qry(nod*2,st,mij,le,min(mij,ri),dim),
               qry(nod*2+1,mij+1,dr,max(mij+1,le),ri,dim));
}
void reset_aint()
{
    for(int i=0;i<4100;i++)
        for(int dim=0;dim<2;dim++)
            aint[i][dim]=-INF;
}
int dp[1001][1001][2];
long long solve()
{
    reset_aint();
    long long rez=-1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            //upd(1,1,m,j,1LL*mat[i][j]+i+j,0);
            //upd(1,1,m,j,1LL*mat[i][j]+i-j,1);
            dp[i][j][0] = max(dp[i-1][j][0], 1LL*mat[i][j]+i+j);
            dp[i][j][1] = max(dp[i-1][j][1], 1LL*mat[i][j]+i-j);
        }
        int mxm=-INF;
        for(int j=1;j<=m;j++)
        {
            mxm=max(mxm, dp[i][j][0]);
            rez = max(rez, mxm-1LL*mat[i][j]-i-j-1);

        }
        mxm=-INF;
        for(int j=m;j>0;j--)
        {
            mxm=max(mxm, dp[i][j][1]);
            rez = max(rez, mxm-1LL*mat[i][j]-i+j-1);
        }
    }
    return rez;
}
signed main()
{
    ios_base::sync_with_stdio(0);

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>mat[i][j];
    long long ceva = solve();
    for(int i=1;i<=n/2;i++)
        for(int j=1;j<=m;j++)
            swap(mat[i][j], mat[n-i+1][j]);
    ceva = max(ceva, solve());
    cout<<ceva;
    return 0;
}
# Verdict Execution time Memory 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 0 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
# 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 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 0 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 852 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory 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 0 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 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 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 104 ms 23848 KB Output is correct
19 Correct 177 ms 32440 KB Output is correct
20 Correct 127 ms 31988 KB Output is correct
21 Correct 117 ms 32320 KB Output is correct
22 Correct 144 ms 32324 KB Output is correct
23 Correct 108 ms 32276 KB Output is correct
24 Correct 120 ms 31892 KB Output is correct