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;
int const N = 105;
LL dp[2][N][N];
LL c[N][N];
int dis[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k, x, y;
cin >> n >> m >> x >> y >> k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> c[i][j];
dp[0][i][j] = -1e18;
}
}
if(k <= 10000){
bool now = 0;
dp[0][x][y] = 0;
while(k--){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
dp[!now][i][j] = -1e18;
for(int s = 0; s < 4; s++){
int tox = i + dis[s][0], toy = j +dis[s][1];
if(tox > 0 && tox <= n && toy > 0 && toy <= m){
dp[!now][i][j] = max(dp[!now][i][j], dp[now][tox][toy]);
}
}
dp[!now][i][j] += c[i][j];
}
}
now = !now;
}
cout << dp[now][x][y];
}
}
# | 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... |