[Community Puzzle] tiling by squares

Raina: If your solution is recursive, use memoization, it will make your code way faster.

bodbod: check the console, you probably output something on the line before the 1. If you used an empty WriteLine for example it outputs a “\n” so it considers that you already answered.

I think this problem is on leetcode I discovered. I read you can use something like valleys or skyline. Where the dp states are the skylines. My understanding is that are filling in the rectangle with all possible squares and generating new skyline states.
This discusses a solution that I believe is along these lines. Although to be honest this code is a bit heavy. Not sure all that is needed.
http://int-e.eu/~bf3/squares/
I believe it is okay to share this link because it doesn’t give a clear solution.

2 Likes

Hello to all :slight_smile: !

My code pass all tests in IDE, but fails in validators 4 & 6 …
-> Can someone help me to know the w & h of these ones, please ?

Thanks, if possible :wink: !

Here you go:

3 Likes

Thanks a lot @TwoSteps : i’ve effectively found a problem in my previous solution handling Validation 6 case …
-> corrected, so now Validator 6 is OK :slight_smile: !

but Validator 4 still reports failure :thinking:
whereas in a real c++ IDE step by step testing mode returns … 7 :dizzy_face: !
=> I can’t understand where is my mistake, please :sleepy: :sleepy: ?
so disappointing …

EDIT : it seems to be a “not responding in time” error …
-> so correction found and apply works :slight_smile: :sweat_smile: !
So : so happy, and thanks many a lot to you !!!
(regrets not to ask for help in time when it was the puzzle of the week :wink: !)

1 Like

Hello,
I have been working on this problem on and off for a month.
I now have what I thought was a good solution but validator 7 still fails. Is there a way to know the parameters (w,h) for this case ?

it’s 23 25 and the expected output is 8

Thanks a lot !
It turns out it was a time out. I found a way to reduce the time for this case and now it’s all good.

I think it’s worth mentionning that the answer should be given in less then 6s (approximately).

Super interesting stuff!

I actually started this problem in May, and gave up only to come back to it now. My code works in my IDE, I get the right results including the validators, which si very satisfying! But it takes too much time in CG (in my IDE, validator 7 takes several minutes). I’m pretty much a beginner, but I enjoy it :slight_smile:

I’m doing a brute force recursion search in C++, starting with the biggest possible squares and decreasing in size with every iteration, and stopping the search after n iterations where n is the previously found minimum number of squares. I think this method is to the order of O(n^2) or even worse, because smaller rectangles are very quick to figure out.

To be continued :slight_smile:

Hi @Pavallin ! if i can give you a :bulb: tip : try to get in memory and reuse (it is possible within the same testcase) the results of your already solved config, instead of solving the same rect again and again :wink:
→ It may give you enough time to parse all successfully !

Have :sun_with_face: sun, fun & Likes :+1: !

1 Like