Friday, October 14, 2011

CF #90

Being lucky that this one is unrated due to author's solution wrong in problem B.

This time I used an unusual strategy and started with problem C. A and B turned out to be trivial enough later so my estimate is correct. B is still tricky in a case when all cards are present in the q cards.

C is a DP problem. Work from day 0 to day n-1, try each hw between a[i] and b[i], and update next state. A state is (hw,day,last), means at that day, use a[last] and b[last], select hw as assignment. Then next state is (hw+k,day+1,l) or (hw*k,day+1,l) for l=last+1 to m-1, assume we sort assignments by increasing c[i]. The problem is made more complicated because we need to return the actual path, so for each state, we need to remember not only total hw so far, but also prev subject, and prev hw. My solution contained 3 mistakes:
1. when declare subject, should use long long for a and b, instead I used int.
2. day is off-by-one when reconstruct path, this should be easy to caught from the testcase, but I simply could not see it.
3. when try nexthw, we have only two options, hw+k and hw*k. I was instead looping over all a[next] to b[next], thinking that the constraints are small enough. However, they are just big enough to make 10^9 which gives a TLE.

After fixing these 3, got AC for problem C.

problem A and B can be done in 10min.

No comments:

Post a Comment