| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1154294 | AgentPengin | Maja (COCI18_maja) | C++20 | 97 ms | 784 KiB | 
/**
 *    author:  AgentPengin ( Độc cô cầu bại )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
#include<bits/stdc++.h>
#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
#define int ll
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 105;
int n, m, a, b, k;
int mat[MAXN][MAXN], pp[MAXN][MAXN];
int dp[2][MAXN][MAXN];
signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (ifstream(NAME".inp")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
    cin >> n >> m >> a >> b >> k;
    for (int i = 1;i <= n;i++) {
    	for (int j = 1;j <= m;j++) cin >> mat[i][j];
    }
    for (int i = 1;i <= n;i++) {
    	for (int j = 1;j <= m;j++) {
    		pp[i][j] = max({mat[i - 1][j], mat[i][j - 1], mat[i + 1][j], mat[i][j + 1]}) + mat[i][j];
    	}
    }
    memset(dp, -0x3f, sizeof dp);
    dp[0][a][b] = 0;
    int ans = 0;
    for (int p = 1;p <= min(k / 2, n * m);p++) {
    	int cur = p & 1;
    	int lst = cur ^ 1;
    	for (int i = 1;i <= n;i++) {
    		for (int j = 1;j <= m;j++) {
    			dp[cur][i][j] = max({dp[lst][i][j - 1], dp[lst][i - 1][j], dp[lst][i + 1][j], dp[lst][i][j + 1]}) + mat[i][j];
    			ans = max(ans, dp[cur][i][j] * 2 - mat[i][j] + pp[i][j] * ((k - p * 2) / 2));
    		}
    	}
    }
    cout << ans;
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
// agent pengin wants to take apio (with anya-san)
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
