From 7148701d25294a01de04792e7d3df2bf6a5263cf Mon Sep 17 00:00:00 2001 From: shiwangi-07 Date: Mon, 15 Apr 2024 01:03:38 +0530 Subject: [PATCH] chore: day 20 --- Medium/Day 20/problem.txt | 28 ++++++++++++++++++++++++++++ Medium/Day 20/sample_tc.txt | 25 +++++++++++++++++++++++++ Medium/Day 20/solution.cpp | 1 + 3 files changed, 54 insertions(+) create mode 100644 Medium/Day 20/problem.txt create mode 100644 Medium/Day 20/sample_tc.txt create mode 100644 Medium/Day 20/solution.cpp diff --git a/Medium/Day 20/problem.txt b/Medium/Day 20/problem.txt new file mode 100644 index 0000000..d738636 --- /dev/null +++ b/Medium/Day 20/problem.txt @@ -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 \ No newline at end of file diff --git a/Medium/Day 20/sample_tc.txt b/Medium/Day 20/sample_tc.txt new file mode 100644 index 0000000..d0cf6a3 --- /dev/null +++ b/Medium/Day 20/sample_tc.txt @@ -0,0 +1,25 @@ +# --> black. +. --> white. + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Sample Input 1: +3 3 +.## +.#. +##. + +Sample Output 1: +1 + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Sample Input 2 +4 4 +..## +#... +###. +###. + +Sample Output 2: +0 \ No newline at end of file diff --git a/Medium/Day 20/solution.cpp b/Medium/Day 20/solution.cpp new file mode 100644 index 0000000..2084d29 --- /dev/null +++ b/Medium/Day 20/solution.cpp @@ -0,0 +1 @@ +// Write your code here. \ No newline at end of file