1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <iostream> #include <cstdio> using namespace std;
const int N = 1e4+66, INF = 250;
int T, res, len; int a, b, i, dy; char p[N], t[N], s[N], f[N];
int main () { scanf ("%d", &T); while (T --> 0) { ++ i; res = a = b = 0; cin >> len; scanf ("%s%s", p+1, t+1); scanf ("%s", s+1); while (1) { dy = a = b = 0; if (res == INF) {res = -1; break;} for (int i = 1; i <= (len<<1); ++ i) f[i] = (i&1 == 1) ? t[++a] : p[++b]; ++ res; for (int i = 1; i <= (len<<1); ++ i) if (f[i] == s[i]) ++ dy; if (dy == (len<<1)) break; for (int i = 1; i <= len; ++ i) p[i] = f[i], t[i] = f[len+i]; } cout << i << ' ' << res << '\n'; } }
|