Input:
N = 3, M = 3, K = 2
Volcano = {{2, 1},
{2, 3}}
Output:
2
Explanation:
at time = 0, only cell (2, 1) and (2, 3)
are filled with lava
at time = 1, cell (1, 1), (2, 1), (3, 1),
(2, 2), (1, 3), (2, 3), (3, 3) are filled
with lava
at time = 2, all cells are filled with lava
What I have tried:
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int solve(int N, int M, int K, vector<vector<int> > Volcano) {
int dp[R][C]=;
int m = R, n = C;
dp[m - 1][n - 1] = points[m - 1][n - 1] > 0
? 1
: abs(points[m - 1][n - 1]) + 1;
for (int i = m - 2; i >= 0; i--)
dp[i][n - 1]
= max(dp[i + 1][n - 1] - points[i][n - 1], 1);
for (int j = n - 2; j >= 0; j--)
dp[m - 1][j]
= max(dp[m - 1][j + 1] - points[m - 1][j], 1);
for (int i = m - 2; i >= 0; i--) {
for (int j = n - 2; j >= 0; j--) {
int min_points_on_exit
= min(dp[i + 1][j], dp[i][j + 1]);
dp[i][j]
= max(min_points_on_exit - points[i][j], 1);
}
}
return Volcano[0][0]=dp[0][0];
}
};