#include "bits/stdc++.h" int main() { int R, K; std::cin >> R >> K; std::string pattern; std::cin >> pattern; int len = pattern.length(); for (int k = 0; k < K; ++k) { std::string next_pattern = pattern; for (int i = 0; i < len; ++i) { int state = 0; if (i != 0) { state |= (pattern[i - 1] == 'X' ? 1 : 0) << 2; } if (i != len-1) { state |= (pattern[i + 1] == 'X' ? 1 : 0); } state |= (pattern[i] == 'X' ? 1 : 0) << 1; bool next = (R >> state) & 0b1; next_pattern[i] = next ? 'X' : '.'; // std::cout << "Iter: " << k << ", bit: " << i << ", state: " << state << ", next: " << next << std::endl; } std::cout << next_pattern << std::endl; pattern = next_pattern; } return 0; }