Skip to content

Commit

Permalink
chore: day 20
Browse files Browse the repository at this point in the history
  • Loading branch information
shiwangi-07 committed Apr 14, 2024
1 parent dc48373 commit 7148701
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Medium/Day 20/problem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Consider a grid with h rows and w columns of squares. Let (r,c) denote the square at the r-th row from the top and the c-th column from the left.
Each square is painted black or white.
The grid is said to be good if and only if the following condition is satisfied:
From (1,1), we can reach (h,w) by moving one square right or down repeatedly, while always being on a white square.
Note that (1,1) and (h,w) must be white if the grid is good.

Your task is to make the grid good by repeating the operation below.

Choose four integers r0, c0, r1, c1 (1 ≤ r0 ≤ r1 ≤ h, 1 ≤ c0 ≤ c1 ≤ w).
For each pair r,c (r0 ≤ r ≤ r1, c0 ≤ c ≤ c1), invert the color of (r, c) - that is, from white to black and vice versa.

Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Input:
First line of input contains two integers h and w (2 <= h, w <= 100).
The next h line contains w integers - value at grid (i, j).

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Output:
Print the minimum number of operations needed.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time Limit: 2 sec
Memory Limit: 1024 MB
25 changes: 25 additions & 0 deletions Medium/Day 20/sample_tc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# --> black.
. --> white.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Input 1:
3 3
.##
.#.
##.

Sample Output 1:
1

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Input 2
4 4
..##
#...
###.
###.

Sample Output 2:
0
1 change: 1 addition & 0 deletions Medium/Day 20/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Write your code here.

0 comments on commit 7148701

Please sign in to comment.