//https://ideone.com/8AsuI2 #include #include #include #include #include #include using namespace std; namespace bitmatrix { typedef unsigned long long ull; struct mat { int n, m; vector> x; mat(int m, int n) : m(m), n(n), x(1+m/8, vector(1+n/8)) { } bool get(int i, int j) const { return x[i/8][j/8] & (1ull << (8*(i%8)+(j%8))); } void set(int i, int j, int b) { if (b) x[i/8][j/8] |= (1ull << (8*(i%8)+(j%8))); else x[i/8][j/8] &= ~(1ull << (8*(i%8)+(j%8))); } }; ostream &operator<<(ostream &os, const mat &A) { for (int i = 0; i < A.m; ++i) { for (int j = 0; j < A.n; ++j) os << A.get(i, j); os << endl; } return os; } mat eye(int n) { mat I(n, n); for (int i = 0; i < I.x.size(); ++i) I.x[i][i] = 0x8040201008040201; return I; } mat add(mat A, const mat &B) { for (int i = 0; i < A.x.size(); ++i) for (int j = 0; j < A.x[0].size(); ++j) A.x[i][j] |= B.x[i][j]; return A; } ull mul(ull a, ull b) { // C[i][j] |= A[i][k] & B[k][j] const ull u = 0xff, v = 0x101010101010101; ull c = 0; for (;a && b; a >>= 1, b >>= 8) c |= (((a & v) * u) & ((b & u) * v)); return c; } mat mul(mat A, mat B) { mat C(A.n, B.m); for (int i = 0; i < A.x.size(); ++i) for (int k = 0; k < B.x.size(); ++k) for (int j = 0; j < B.x[0].size(); ++j) C.x[i][j] |= mul(A.x[i][k], B.x[k][j]); return C; } mat pow(mat A, long long k) { mat X = eye(A.n); for (; k > 0; k >>= 1) { if (k & 1ll) X = mul(X, A); A = mul(A, A); } return X; } ull transpose(ull a) { ull t = (a ^ (a >> 7)) & 0xaa00aa00aa00aa; a = a ^ t ^ (t << 7); t = (a ^ (a >> 14)) & 0xcccc0000cccc; a = a ^ t ^ (t << 14); t = (a ^ (a >> 28)) & 0xf0f0f0f0; a = a ^ t ^ (t << 28); return a; } mat transpose(mat A) { mat B(A.m, A.n); for (int i = 0; i < A.x.size(); ++i) for (int j = 0; j < A.x[0].size(); ++j) B.x[j][i] = transpose(A.x[i][j]); return B; } } using namespace bitmatrix; int main() { int n; cin >> n; long long t; cin >> t; mat A(n, n); string s; for(int i=0;i> s; for(int j=0;j