Submission #304823

# Submission time Handle Problem Language Result Execution time Memory
304823 2020-09-22T00:37:58 Z shrek12357 Maja (COCI18_maja) C++14
44 / 110
5 ms 640 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

long long best(long long a, long long b, long long c, long long d) {
	return max(max(a, b), max(c, d));
}

int main() {
	long long n, m, a, b, k;
	cin >> n >> m >> a >> b >> k;
	a--;
	b--;
	long long grid[105][105];
	long long dp[105][105];
	bool vis[105][105];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> grid[i][j];
			dp[i][j] = -1e9;
			vis[i][j] = false;
		}
	}
	dp[a][b] = 0;
	vis[a][b] = true;
 	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();
		vis[x][y] = true;
		if (x < 0 || x >= n || y < 0 || y >= m || dp[x][y] >= 0) {
			continue;
		}
		long long t1 = 0, t2 = 0, t3 = 0, t4 = 0;
		if (x - 1 >= 0) {
			t1 = max(dp[x - 1][y], t1);
		}
		if (x + 1 < n) {
			t2 = max(dp[x + 1][y], t2);
		}
		if (y - 1 >= 0) {
			t3 = max(dp[x][y - 1], t3);
		}
		if (y + 1 < m) {
			t4 = max(dp[x][y + 1], t4);
		}
		dp[x][y] = best(t1, t2, t3, t4) + grid[x][y];
		if(x + 1 < n && !vis[x + 1][y])
		check.push({ x + 1, y });
		if(x - 1 >= 0 && !vis[x - 1][y])
		check.push({ x - 1, y });
		if(y + 1 < m && !vis[x][y + 1])
		check.push({ x, y + 1 });
		if(y - 1 >= 0 && !vis[x][y - 1])
		check.push({ x, y - 1 });
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			long long diff = max(i - a, a - i) + max(j - b, b - j);
			long long 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 5 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -