# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92158 | Kastanda | Maja (COCI18_maja) | C++11 | 100 ms | 632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, k, a, b, A[N][N];
long long MX, dp[2][N][N];
int main()
{
scanf("%d%d%d%d%d", &n, &m, &a, &b, &k);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &A[i][j]);
memset(dp, -63, sizeof(dp));
dp[0][a][b] = 0;
for (int len = 1, w = 1; len <= n * m && len * 2 <= k; len ++, w = !w)
{
for (int i = 1; i <= n; i++)
for (int j = (a + b + i + (!w)) % 2 + 1; j <= n; j += 2)
{
dp[w][i][j] = max({dp[!w][i-1][j] + A[i-1][j], dp[!w][i+1][j] + A[i+1][j],
dp[!w][i][j-1] + A[i][j-1], dp[!w][i][j+1] + A[i][j+1]});
int sum = A[i][j] + max({A[i-1][j], A[i+1][j], A[i][j-1], A[i][j+1]});
MX = max(MX, dp[w][i][j] * 2LL + ((k >> 1) - len) * 1LL * sum + A[i][j]);
}
}
return !printf("%lld\n", MX);
}
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... |