/* -*- coding: utf-8 -*- * * 197.cc: No.197 手品 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int BITS = 1 << 8; /* typedef */ /* global variables */ int fs[BITS], cs[BITS], used[BITS]; /* subroutines */ int s2i(string &s) { int r = 0; for (int i = 0; i < 3; i++) if (s[i] == 'o') r |= (1 << i); return r; } int swapbit(int bits, int i, int j) { int bi = ((bits >> i) & 1); int bj = ((bits >> j) & 1); return (bits & ~(1 << i) & ~(1 << j)) | (bi << j) | (bj << i); } /* main */ int main() { for (int bits = 0; bits < BITS; bits++) { fs[bits] = 0; for (int i = 0, bi = 1; i < 8; i++, bi <<= 1) if (bits & bi) fs[bits] |= (1 << swapbit(i, 0, 1)) | (1 << swapbit(i, 1, 2)); } string sst, sgl; int n; cin >> sst >> n >> sgl; int st = s2i(sst); int gl = s2i(sgl); cs[0] = 1 << st; memset(used, -1, sizeof(used)); used[1 << st] = 0; int i0 = 0, i1; for (i1 = 1; i1 < BITS; i1++) { int nc = fs[cs[i1 - 1]]; if (used[nc] >= 0) { i0 = used[nc]; break; } cs[i1] = nc; used[nc] = i1; } //printf("%d,%d\n", i0, i1); //for (int i = 0; i < i1; i++) printf("%02x ", cs[i]); putchar('\n'); int k = (n < i0) ? n : (n - i0) % (i1 - i0) + i0; bool ok = ((cs[k] & (1 << gl)) == 0); cout << (ok ? "SUCCESS" : "FAILURE") << endl; return 0; }