Segment Sum
HardRating 2300CodeforcesAdvanced DP (Bitmask, Digit, Interval)
Approach hintTry it first, then revealHide
Digit DP over position, the mask of digits used, a tight flag and a leading-zero flag. Store both the number of valid completions and the sum of their values, so placing digit c at weight 10^p adds c * 10^p * count.