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>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 110;
const int PW = 22;
int c[N][N], a, b, n, m, k;
ll ans[2][N][N];
void MAX(ll &x, ll y){
x = max(x, y);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> a >> b >> k;
a--; b--;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> c[i][j];
ans[0][a][b] = 1;
int it = 0;
for (int ite = 1; ite <= k; ite++){
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans[it ^ 1][i][j] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++){
if (ans[it][i][j] == 0) continue;
if (i > 0) MAX(ans[it ^ 1][i - 1][j], ans[it][i][j] + c[i - 1][j]);
if (j > 0) MAX(ans[it ^ 1][i][j - 1], ans[it][i][j] + c[i][j - 1]);
if (j + 1 < m) MAX(ans[it ^ 1][i][j + 1], ans[it][i][j] + c[i][j + 1]);
if (i + 1 < n) MAX(ans[it ^ 1][i + 1][j], ans[it][i][j] + c[i + 1][j]);
}
it ^= 1;
}
cout << ans[it][a][b] - 1;
return 0;
}
# | 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... |