#pragma GCC optimize "O3" #include using namespace std; typedef long long ll; typedef long double ld; typedef pair ii; typedef vector vi; typedef vector vii; #define FOR(i,b,e) for(int i=b; i<=e; i++) #define FORD(i,b,e) for(int i=b; i>=e; i--) #define SIZE(x) ((int)x.size()) #define pb push_back #define st first #define nd second #define sp ' ' #define ent '\n' int t, m, n; pair plan[22][22]; pair nplan[22][22]; int mapa[22][22]; void przypisz(){ FOR(i, 0, m){ FOR(j, 0, n){ plan[i][j]=nplan[i][j]; nplan[i][j]={0, 0}; } } } void simulate(){ FOR(i, 0, m){ FOR(j, 0, n){ if(plan[i][j].st=='S'){ int kom=(i+1)%(m+1); nplan[kom][j]=plan[i][j]; //owca idzie nplan[kom][j].nd++; } } } FOR(i, 0, m){ FOR(j, 0, n){ if(plan[i][j].st=='W'){ int kom=(j+1)%(n+1); if(nplan[i][kom].st=='S'){ //wilk je owce plan[i][j].nd=-1; mapa[i][kom]=4; } nplan[i][kom]=plan[i][j]; //wilk idzie nplan[i][kom].nd++; } } } FOR(i, 0, m){ FOR(j, 0, n){ if(nplan[i][j].st=='S' && mapa[i][j]==3){ //owca je nplan[i][j].nd=0; mapa[i][j]=-1; } if(mapa[i][j]!=3) mapa[i][j]++; //trawa rosnie } } FOR(i, 0, m){ FOR(j, 0, n){ if(nplan[i][j]==make_pair('S', 5) || nplan[i][j]==make_pair('W', 10)){//umiera mapa[i][j]=4; nplan[i][j]={0, 0}; } } } przypisz(); } void wypisz(){ FOR(i, 0, m){ FOR(j, 0, n){ if(plan[i][j].st=='S' || plan[i][j].st=='W') cout<>t>>m>>n; m--; n--; FOR(i, 0, m){ FOR(j, 0, n){ cin>>c; if(c!='.') plan[i][j]={c, 0}; } } FOR(i, 1, t) simulate(); wypisz(); } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; } /* 6 6 5 ..S.. ..... .S... ..... ....W .S... 14 3 3 S.. W.. ... 2 3 1 S . . 3 3 1 S . . 4 3 1 S . . 5 3 1 S . . */