935D: Fafa and Ancient Alphabet

DP idea is simple, but I got stuck at calculating modular inverse, because I didn’t know Fermat’s Little Theorem!!!

LL inverse (LL num) { return quickPower(num, 1000000007 - 2); }

939D: Love Rescue

Number letters - number of connected components

400D:Dima and Bacteria

  1. ignore all cost > 0 edges, this means all vs with same type should be within the same component => correctness check!!!

  2. add all edges with cost only to the first B of a type, and then run floyd-warshall

845D:Driving test

keep track of signs in effect and add events one by one, if potentially violates the sign, ignore

253C:Text Editor

We can delay shift left/right as much as we can

799D: Field expansion

two choices: h to a or h to b