The last css rule that appears will apply to the entire page and override any previous css. So this approach certainly will not work to get different spacing for problems on the same page.
The only way to achieve different spacing for different problems on the same page would be to edit the problems and inject a css class into those answers, and then apply css to those classes.