Need help in identifying why my approach fails

Правка en1, от dorasainath955, 2025-01-13 14:41:33

Submission
Problem

Approach

make the row and column sums to be equal to zero in other words let $$$x=0$$$ then construct the matrix
  1. Create two vectors call them as "row_sums" and "col_sums".
    $$$RowSums[i]$$$ corresponds to sum of all elements in $$$row_{i}$$$
    Same goes for col_sums

given $$$A = n\times m$$$ matrix, where it's always the case that $$$A_{1, 1}=0$$$(one based index), here we have 2 options to go to from $$$A_{1,1}$$$

  • Go right
  • Go down

Right

Going right indirectly means that $$$A_{i, 1} $$$ where $$$i \in [2, n]$$$ for all $$$i$$$ are never went missing these values are unchanged, find column-1 sum then replace $$$A_{1,1}=0$$$ with $$$A_{1,1}=-\sum_{i=1}^{n}{A_{i, 1}}$$$ since $$$A_{1, 1}=0$$$ we can take summation without having to worry about subtracting $$$A_{1,1}$$$ from the column sum
Then update the col_sums and row_sums array. col_sums[1] += $$$A_{1,1}$$$ and row_sums[1] += $$$A_{1,1}$$$
Update the position of the current indexes based on the next character value that comes from string s. if next character is D then increase the row index by 1. if next character is R update column index by 1.

Down

Going Down indirectly means that $$$A_{1, j} $$$ where $$$j \in [2, m]$$$ for all $$$j$$$ are never went missing these values are unchanged, find row-1 sum then replace $$$A_{1,1}=0$$$ with $$$A_{1,1}=-\sum_{j=1}^{m}{A_{1, j}}$$$ since $$$A_{1, 1}=0$$$ we can take summation without having to worry about subtracting $$$A_{1,1}$$$ from the row sum
Then update the col_sums and row_sums array. col_sums[1] += $$$A_{1,1}$$$ and row_sums[1] += $$$A_{1,1}$$$
Update the position of the current indexes based on the next character value that comes from string s. if next character is D then increase the row index by 1. if next character is R update column index by 1.

Repeat the process for all missing values

In the code I've Linked i used pair<int, int>current_pos, current_pos.first to track current row positon and current_pos.second to track current column position.
Теги constructive algorithms, greedy, math, brute force, matrix

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский dorasainath955 2025-01-13 14:41:33 2353 Initial revision (published)