voidinit(){ staticbool first = true; if (!first) { return; } first = false; for (int i = 0; i < 27; i++) { int first = getFirst(i); int second = getSecond(i); int third = getThird(i); if (first != second && second != third) { okList.push_back(i); } } } public: intnumOfWays(int n){ init(); longlong a[27] = {0}; longlong b[27] = {0}; for (int t : okList) { a[t] = 1; }
while (--n) { for (int first : okList) { for (int second : okList) { if (isOk(first, second)) { b[second] = (b[second] + a[first]) % MOD; } } } swap(a, b); memset(b, 0, sizeof(b)); } returnaccumulate(a, a + 27, 0ll) % MOD; } };