What is it in the 2019 South China University of Technology? Is there any empty? Can you come to alchem? (Thinking of thinking)

https://ac.nowcoder.com/acm/contest/625/B

Analysis:

All status is only 1<< 18, so we can preprocess f[u][j], and then build a state diagram of all the states that u can transfer;