Sunday, February 12, 2012

CF 106 div2

A: sort to decreasing order, take elements till >=k, watch for k=0 and -1
B: the only -1 case is when both hh and mm are single digit. Otherwise check r=base to 60. base is max digit already show up +1
C: sort increasingly and assign alternatively will work. The induction proof relies on that previous diff is no more than next element.
D: DP with calc(begin, end, c1, c2) computes #coloring with [begin,end) and begin-1 has c1 and end has c2. Need to consider two cases, (...) and (...)( ), and enumerate all 0,1,2 coloring.
E: forward and backward KMP to compute front[] and back[] where front[i] is longest prefix that matches s[0..i] and back is the longest suffix that matches s[n-1..n-1-i]. reverse s[] to compute back[]. To implement KMP needs some careful indexing and initialization. Watch for off-by-one and index-out-of-bounds.

No comments:

Post a Comment