#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
int best(int a, int b, int c, int d) {
return max(max(a, b), max(c, d));
}
int main() {
int n, m, a, b, k;
cin >> n >> m >> a >> b >> k;
a--;
b--;
int grid[105][105];
int dp[105][105];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
dp[i][j] = (int)-1e9;
}
}
dp[a][b] = 0;
queue<pair<int, int>> check;
check.push({ a + 1, b });
check.push({ a - 1, b });
check.push({ a, b - 1 });
check.push({ a, b + 1 });
while (check.size() > 0) {
int x = check.front().first, y = check.front().second;
check.pop();
if (x < 0 || x >= n || y < 0 || y >= m || dp[x][y] >= 0) {
continue;
}
dp[x][y] = best(dp[x - 1][y], dp[x + 1][y], dp[x][y - 1], dp[x][y + 1]) + grid[x][y];
check.push({ x + 1, y });
check.push({ x - 1, y });
check.push({ x, y + 1 });
check.push({ x, y - 1 });
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int diff = max(i - a, a - i) + max(j - b, b - j);
int cur = best(grid[i - 1][j], grid[i + 1][j], grid[i][j - 1], grid[i][j + 1]) + grid[i][j];
ans = max(ans, dp[i][j] + dp[i][j] - grid[i][j] + (k - diff * 2) / 2 * cur);
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
269 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2091 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
385 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
276 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
411 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
287 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
251 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
292 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |