Submission #87376

# Submission time Handle Problem Language Result Execution time Memory
87376 2018-11-30T15:41:26 Z luckyboy Maja (COCI18_maja) C++14
110 / 110
802 ms 852 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 105
#define maxm 500005
#define pii pair <int,int>
#define Task "Maja"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,m,a,b,k,f[maxn][maxn],dd[maxn][maxn];
long long dp[2][maxn][maxn],ans;
int xx[] = {1,-1,0,0};
int yy[] = {0,0,1,-1};
int Recode(int x,int y)
{
    return (x - 1) * m + y;
}
bool Inside(int x,int y)
{
    return x >= 1 && x <= n && y >= 1 && y <= m;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n >> m >> a >> b >> k;
    k >>= 1;
    int lim = min(k,n*m-1);
    FOR(i,1,n) FOR(j,1,m) cin >> f[i][j];
    FOR(i,0,1) FOR(j,1,n) FOR(h,1,m) dp[i][j][h] = -1ll*maxc*maxc;
    dp[0][a][b] = 0;
    FOR(h,1,lim)
        {
            bool st = h & 1;
            FOR(i,1,n)
                FOR(j,1,m)
                    FOR(h,0,3)
                    {
                        int u = i + xx[h],
                            v = j + yy[h];
                        if (Inside(u,v))
                        {
                            dp[st][u][v] = max(dp[st][u][v],dp[!st][i][j] + f[u][v]);
                        }
                    }
        }
    bool st = lim & 1;
    FOR(i,1,n)
        FOR(j,1,m)
        {
            int cur = 0;
            FOR(h,0,3)
                {
                    int u = i + xx[h],
                        v = j + yy[h];
                    cur = max(cur,f[u][v] * Inside(u,v));
                }
            ans = max(ans,dp[st][i][j] * 2 + 1ll*(k - lim) * (cur + f[i][j]) - f[i][j]);
        }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 4 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 516 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 644 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
3 Correct 754 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 824 KB Output is correct
2 Correct 463 ms 824 KB Output is correct
3 Correct 802 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 852 KB Output is correct
2 Correct 672 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 852 KB Output is correct
2 Correct 45 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 852 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct