codeforces solution
codeforces solution
#include <vector>
#include <string>
#include <numeric>
if (!p[i][j]) {
r_sums[i] += g[i][j];
c_sums[j] += g[i][j];
int main() {
int t;
cin >> t;
while (t--) {
int r, c;
string ps;
path.push_back({0, 0});
if (d == 'D') row++;
else col++;
path.push_back({row, col});
is_path[cell.first][cell.second] = true;
vector<vector<int>> final_g = g;
int r1 = path[k].first;
int c1 = path[k].second;
final_g[r1][c1] = val;
} else {
final_g[r1][c1] = val;
if (!path.empty()) {
final_g[last_r][last_c] = val_r;
return 0;