TestTrial's blog

By TestTrial, history, 3 years ago, In English

I'm pretty dumbfounded with 15A(15A - Cottage Village). I thought I figured this problem out yet there seems I still miss something. I get a wrong answer for case 11 which is too big to manually check, yet I've got no further ideas on how to improve my code. Any visible flaws or missed points?

My idea was to sort all the x-coordinates of houses' endpoints and iterate with i+=2 (to avoid overlapping houses) over them and check whether another house fits perfectly (count++) or if some space is still left for another possibility (count+=2).

Here is my submission: 112622985

Any help is greatly appreciated. Thanks a bunch

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +23 Vote: I do not like it

Have you tried the following:

  • Write a very naive and simple solution to the problem (maybe exponential complexity) (if you can, you may also just copy someone else's solution)
  • Write a program to generate thousands of small (!) test cases
  • Using those two, find a test case where your program gives the wrong answer
  • Use print statements or a debugger to see where exactly your program does the wrong thing.

98% of WAs and REs can be resolved this way. People here don't have the time to delve into every code posted here, it's much harder to debug somebody else's code and being able to debug your own code is a valuable skill. It is also a very routine process that can be learned much faster than problem solving and algorithms.