Sounds like my experience last semester.
I realised how to do a difficult question just as the invigilators
told us to put our pens down. 
Anyway, like I said before, don't bother ruminating over it... the
best thing you can do right now is to prepare for the next paper
and to do your best for it. 