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;
typedef long long ll;
const int maxn = 105;
int c[maxn][maxn];
ll dp[2][maxn][maxn];
int main(){
ios_base::sync_with_stdio(false);
int n, m, k, a, b;
cin >> n >> m >> a >> b >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> c[i][j];
ll answer = 0;
memset(dp, -63, sizeof dp);
dp[0][a][b] = 0;
for (int len = 1; len <= n * m && len * 2 <= k; len ++){
int w = len & 1;
for (int i = 1; i <= n; i++){
for (int j = (a + b + i + (!w)) % 2 + 1; j <= m; j += 2){
dp[w][i][j] = max({dp[!w][i-1][j] + c[i-1][j], dp[!w][i+1][j] + c[i+1][j],
dp[!w][i][j-1] + c[i][j-1], dp[!w][i][j+1] + c[i][j+1]});
int sum = c[i][j] + max({c[i-1][j], c[i+1][j], c[i][j-1], c[i][j+1]});
answer = max(answer, dp[w][i][j] * 2LL + ((k >> 1) - len) * 1LL * sum + c[i][j]);
}
}
}
cout << answer << '\n';
}
# | 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... |