이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |