64602023-12-02 14:36:11111Jegesmedve (50)cpp17Elfogadva 50/50237ms5436 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

#define MOD 20200111

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be2.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, M;
	cin >> N >> M;
	int i0, j0;
	int a[100][100];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> a[i][j];
			if (a[i][j] == -1) {
				a[i][j] = INT_MAX;
				i0 = i;
				j0 = j;
			}
		}
	}
	int b[100][100];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> b[i][j];
		}
	}
	int v[100][100] {};
	auto dfs = [&](auto dfs, int i, int j, int x) {
		if (i < 0 || i >= N || j < 0 || j >= M || v[i][j] >= x) {
			return;
		}
		v[i][j] = min(x, a[i][j]);
		dfs(dfs, i + 1, j, v[i][j]);
		dfs(dfs, i - 1, j, v[i][j]);
		dfs(dfs, i, j + 1, v[i][j]);
		dfs(dfs, i, j - 1, v[i][j]);
	};
	dfs(dfs, i0, j0, INT_MAX);
	map<int, int> m;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			m[v[i][j]] += b[i][j];
		}
	}
	int ans = 0;
	for (auto p : m) {
		ans = min(p.first, ans + p.second);
	}
	cout << ans + 1 << endl;
	return 0;
}

RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2316 KiB
2Elfogadva0/03ms2584 KiB
3Elfogadva3/33ms2728 KiB
4Elfogadva3/33ms3092 KiB
5Elfogadva3/33ms3228 KiB
6Elfogadva4/44ms3316 KiB
7Elfogadva3/33ms3552 KiB
8Elfogadva3/33ms3636 KiB
9Elfogadva3/33ms3696 KiB
10Elfogadva4/43ms3672 KiB
11Elfogadva4/414ms4064 KiB
12Elfogadva4/48ms4096 KiB
13Elfogadva4/44ms4000 KiB
14Elfogadva4/4100ms4812 KiB
15Elfogadva4/4158ms5252 KiB
16Elfogadva4/4237ms5436 KiB