#include using namespace std; int main() { int v, d; cin >> v >> d; d = min(d, v+998); // offset less than 998 fails to get AC (nande???) using bs = bitset<1000>; vector E(v); for (auto& i : E) { string str; cin >> str; reverse(str.begin(), str.end()); i = bs(str); } const int pwrdp = 11; // 2^11 > V + 998 > 2^10 vector> dp(pwrdp, vector(v)); dp[0] = E; // log D for (int i = 1; i < pwrdp; ++i) { // V for (int j = 0; j < v;++j){ // min(V, D) for (int k = dp[i - 1][j]._Find_first(); k < v; k = dp[i - 1][j]._Find_next(k)) { dp[i][j] |= dp[i - 1][k]; } } } vector Rchbl(v), x, emp(v); for (int i = 0; i < v; ++i) Rchbl[i].set(i); // log D for (int di = 0, dd = d; dd > 0; ++di, dd /= 2) { if (dd & 1) { x = emp; // V for (int i = 0; i < v; ++i) { // min(V, D) for (int j = Rchbl[i]._Find_first(); j < v; j = Rchbl[i]._Find_next(j)) { // V/w x[i] |= dp[di][j]; } } Rchbl = x; } } // V for (int i = 0; i < v; ++i) if (Rchbl[i].count() < v) return cout << "No" << endl, 0; cout << "Yes" << endl; }