#include #define MOD 1000000007 #define ll long long using namespace std; #define TTT 3 int main() { ll T, N, M; scanf("%lli %lli %lli", &T, &N, &M); ll grass[M][N]; ll carcass[M][N]; ll wolfmap[M][N]; ll sheepmap[M][N]; ll sheep_x[400] = {}; ll sheep_y[400] = {}; ll sheep_a[400] = {}; ll sheep_n = 0; ll wolf_x[400] = {}; ll wolf_y[400] = {}; ll wolf_a[400] = {}; ll wolf_n = 0; for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) { grass[x][y] = 0; carcass[x][y] = 0; char c; scanf(" %c", &c); if(c == 'S' ) { sheep_x[sheep_n] = x; sheep_y[sheep_n] = y; sheep_a[sheep_n] = 0; sheep_n++; continue; } if(c == 'W' ) { wolf_x[wolf_n] = x; wolf_y[wolf_n] = y; wolf_a[wolf_n] = 0; wolf_n++; continue; } } for(int t = 1; t <= T; t++) { // 1 for(int i = 0; i < sheep_n; i++) sheep_y[i] = (sheep_y[i]+1)%N; for(int i = 0; i < wolf_n; i++) wolf_x[i] = (wolf_x[i]+1)%M; // 2 for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) wolfmap[x][y] = -1; for(int i = 0; i < wolf_n; i++) wolfmap[wolf_x[i]][wolf_y[i]] = i; for(int i = 0; i < sheep_n; i++) { ll w = wolfmap[sheep_x[i]][sheep_y[i]]; if(w > -1) { carcass[sheep_x[i]][sheep_y[i]] = 1; wolf_a[w] = t; sheep_n--; sheep_x[i] = sheep_x[sheep_n]; sheep_y[i] = sheep_y[sheep_n]; sheep_a[i] = sheep_a[sheep_n]; i--; } } // 3 for(int i = 0; i < sheep_n; i++) { if(t - grass[sheep_x[i]][sheep_y[i]] > TTT && !carcass[sheep_x[i]][sheep_y[i]]) { grass[sheep_x[i]][sheep_y[i]] = t; sheep_a[i] = t; } } // 4 for(int i = 0; i < wolf_n; i++) { if(t - wolf_a[i] >= 10) { carcass[wolf_x[i]][wolf_y[i]] = 1; wolf_n--; wolf_x[i] = wolf_x[wolf_n]; wolf_y[i] = wolf_y[wolf_n]; wolf_a[i] = wolf_a[wolf_n]; i--; } } // 5 for(int i = 0; i < sheep_n; i++) { if(t - sheep_a[i] >= 5) { carcass[sheep_x[i]][sheep_y[i]] = 1; sheep_n--; sheep_x[i] = sheep_x[sheep_n]; sheep_y[i] = sheep_y[sheep_n]; sheep_a[i] = sheep_a[sheep_n]; i--; } } /////////////////////// /* printf("\n"); printf("\n"); printf("\n"); printf("%i\n", t); for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) sheepmap[x][y] = -1; for(int i = 0; i < sheep_n; i++) sheepmap[sheep_x[i]][sheep_y[i]] = i; for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) wolfmap[x][y] = -1; for(int i = 0; i < wolf_n; i++) wolfmap[wolf_x[i]][wolf_y[i]] = i; for(int y = 0; y < N; y++){ for(int x = 0; x < M; x++) { if(wolfmap[x][y] > -1) { printf("W"); continue;} if(sheepmap[x][y] > -1) { printf("S"); continue;} if(carcass[x][y]) { printf("*"); continue;} if(t-grass[x][y] >= 3) { printf("#"); continue;} printf("."); } printf("\n"); } */ ////////////////////// } /* printf("\n"); printf("\n"); printf("\n");*/ for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) sheepmap[x][y] = -1; for(int i = 0; i < sheep_n; i++) sheepmap[sheep_x[i]][sheep_y[i]] = i; for(int y = 0; y < N; y++) for(int x = 0; x < M; x++) wolfmap[x][y] = -1; for(int i = 0; i < wolf_n; i++) wolfmap[wolf_x[i]][wolf_y[i]] = i; for(int y = 0; y < N; y++){ for(int x = 0; x < M; x++) { if(wolfmap[x][y] > -1) { printf("W"); continue;} if(sheepmap[x][y] > -1) { printf("S"); continue;} if(carcass[x][y]) { printf("*"); continue;} if(T-grass[x][y] > TTT-1) { printf("#"); continue;} printf("."); } printf("\n"); } }