Simple case : (0 0)(2 2)(4 4) -> 8 (100 pts)
Unordonate positions : (2 3)(1 1)(4 4) -> 6 (100 pts)
Pair N : (1 2)(0 0)(2 2)(5 3) -> 8 (100 pts)
If N = 1 then L = 0 (100 pts)
Negative positions (-5 -3)(-9 2)(9 -4) -> 24 (100 pts)
Works when 2^32 < L < 2^63 (100 pts)
Works in time when N = 100000 and L < 2^31 (200 pts)
Works in time when N = 99999 (every x and y are distincts) (200 pts)
Highly dispersed positions (200 pts)
Readability Analysis
Method IL Size: 282. Maximum Size: 165 (Long methods are usually hard to understand and maintain. This method can cause problems because it contains more code than the maximum allowed.)
My code fails on âHighly dispersed positionsâ test
Where is problem? What is âMaximum Size: 165â parameter?
My code have about 120 rowsâŚ
@Revernus When I first saw the drawings for this test, I found it looked like fitting a 0-degree polynomial for which the answer is the mean of the Ys when using least-square method (there is only 1 parameter).
Well after trying I found out like you guys that the proper answer is indeed the median, not the mean. My guess is that we shouldnât think to minimize the squares of the difference but rather the absolute values.
I think this is a brilliant example that associating something simple with something complex as I did makes you think hours for futilities. The best was to think like @BlitzProg ⌠So I had to come here and comment this game: brilliant.
@alec_m_melnikoff it looks like hard coding for 120 rows, it might be the reason why⌠(see comments above)
Iâve tried another approach. Evaluate mean Y as double and then find the nearest existing Y. It works in IDE for all tests but fails on validation on âWorks in time when N = 100000 and L < 2^31â.
Canât see why.
I got the same issue as Sebastien.
I fail for : 2^32 < L < 2^63
But I donât know why, I use long long to be sure⌠this shouldnât have any problem, but itâs not okâŚ
I pass any other test.
Thanks if someone has idea.
Hello,
As Iâve read posts above, some of you were stuck at certain test cases.
Personally, Iâve been stuck using Groovy at : "Works in time when N = 100000 and L < 2^31 (200 pts)"
But, after translating my program to Java, it passes all test cases !
It might be that Groovy is relatively slow comparing to JavaâŚ
Looks like there is an error in the task validation. I used iterative algorithm to find the optimal solution, so it is hard to make a mistake there. So letâs take a look on the data of the test case #7. I found houses with the same X value and reduced the search range between Y values of the houses. In the next lines we have 2 houses with X values and the search interval from min Y to max Y, letâs name variables as (xi, yi) (xj, yj) y0 y1:
Thus, when y0 < min(yi,yj) < y1 then we update y0=min(yi,yj);
when y0 < max(yi,yj) < y1 we update y1=max(yi,yj).
So in the example above the search interval converges to [1.0, 3.0]. In the whole test, final search range is [1.0,1.0], but optimal solution is at 0, which means there are at least two houses that are connected to the main cable with a single cable.
My algorithm (without search range narrowing) passes all the IDEâs test cases and all validation tests except for the last one.