#include #include #include int dxs[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }; int dys[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; using namespace std; int main() { int R, C; long S; ifstream fin("flowfield.in"); fin >> C >> R >> S; vector> dx(R), dy(R); vector> points[2]; points[0].resize(R); points[1].resize(R); for (int r = 0; r < R; r++) { dx[r].resize(C); dy[r].resize(C); points[0][r].resize(C); points[1][r].resize(C); for (int c = 0; c < C; c++) { int dir; fin >> dir; dx[r][c] = dxs[dir]; dy[r][c] = dys[dir]; points[0][r][c] = 1; points[1][r][c] = 0; } } bool equal = false; long s; for (s = 0; !equal && s < S; s++) { int i = s & 1, o = 1 - i; for (int r = 0; r < R; r++) { for (int c = 0; c < C; c++) { int in = points[i][r][c]; if (in > 0) { int c1 = c + dx[r][c], r1 = r + dy[r][c]; if (c1 >= 0 && c1 < C && r1 >= 0 && r1 < R) points[o][r1][c1] += in; } } } equal = true; for (int r = 0; r < R; r++) { for (int c = 0; c < C; c++) { if (points[0][r][c] != points[1][r][c]) equal = false; points[i][r][c] = 0; } } } ofstream fout("flowfield.out"); for (int r = 0; r < R; r++) { for (int c = 0; c < C; c++) { if (c > 0) fout << " "; fout << points[s & 1][r][c]; } fout << endl; } return 0; }