#include #include #include // state is (state1) (state2) (status) // status is: // '-' identical (0) // 'x' identical except string 1 ends with character x (1-26) // '!' permanently different (27) // In our search we use the following metatransitions: // - x ! // simultaneous - ! ! // lowercase on string 1 x x ! // lowercase on string 2 * ! ! // * = we don't permit this transition using namespace std ; using ll = long long ; const int MAXS = 64 ; const int STAT = 28 ; const int INF = 2000000000 ; int dist[MAXS][MAXS][STAT] ; int nextstate[MAXS][52] ; ll havetrans[MAXS] ; int main() { int s, p, t ; cin >> s >> p >> t ; vector isfinal(s) ; for (int i=0; i> a ; a-- ; isfinal[a] = 1 ; } for (int i=0; i> a >> sigma >> b ; a-- ; b-- ; int c = (sigma <= 'Z' ? (sigma - 'A') : (sigma - 'a' + 26)) ; nextstate[a][c] = b ; havetrans[a] |= 1LL< 0 && stat < 27 ? 27 : stat) ; dist[ns0][ns1][nstat] = min(dist[ns0][ns1][nstat], tim+2) ; } } int lc0 = havetrans[s0] >> 26 ; while (lc0) { int c = ffs(lc0) - 1 ; lc0 &= ~(1< 0) { int lc1 = havetrans[s1] >> 26 ; while (lc1) { int c = ffs(lc1) - 1 ; lc1 &= ~(1<