可能有點冗長 但大概是我能想出來的解法了
https://github.com/Neil-Lin-0404/ZeroJudge-Problems-Solution-CPP/blob/main/dXXX/d984.cpp