Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz size
- #define ll long long
- #define ld long double
- #define fs first
- #define sc second
- #define forn(i, f, t) for(int i = f; i < t; i++)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- pair<int, int> pos = mp(-1, -1), lst;
- int a[21][21], n, m;
- bool lost = 0, ap = 0;
- string s[21];
- pair<int, int> getNext(pair<int, int> p){
- switch (a[p.fs][p.sc]){
- case 0: return mp(p.fs - 1, p.sc);
- case 1: return mp(p.fs, p.sc + 1);
- case 2: return mp(p.fs + 1, p.sc);
- case 3: return mp(p.fs, p.sc - 1);
- }
- }
- void move(char c){
- if (c == 'L' && pos.sc == 0){lost = 1; return;}
- else if (c == 'L'){
- if (s[pos.fs][pos.sc - 1] == 'S'){lost = 1; return;}
- a[pos.fs][pos.sc] = 3;
- if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
- if (s[pos.fs][pos.sc - 1] == 'A') ap = 1;
- else ap = 0;
- s[pos.fs][pos.sc - 1] = 'S';
- pos.sc--;
- }
- if (c == 'D' && pos.fs == n - 1){lost = 1; return;}
- else if (c == 'D'){
- if (s[pos.fs + 1][pos.sc] == 'S'){lost = 1; return;}
- a[pos.fs][pos.sc] = 2;
- if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
- if (s[pos.fs + 1][pos.sc] == 'A') ap = 1;
- else ap = 0;
- s[pos.fs + 1][pos.sc] = 'S';
- pos.fs++;
- }
- if (c == 'R' && pos.sc == m - 1){lost = 1; return;}
- else if (c == 'R'){
- if (s[pos.fs][pos.sc + 1] == 'S'){lost = 1; return;}
- a[pos.fs][pos.sc] = 1;
- if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
- if (s[pos.fs][pos.sc + 1] == 'A') ap = 1;
- else ap = 0;
- s[pos.fs][pos.sc + 1] = 'S';
- pos.sc++;
- }
- if (c == 'U' && pos.fs == 0){lost = 1; return;}
- else if (c == 'U'){
- if (s[pos.fs - 1][pos.sc] == 'S'){lost = 1; return;}
- a[pos.fs][pos.sc] = 0;
- if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
- if (s[pos.fs - 1][pos.sc] == 'A') ap = 1;
- else ap = 0;
- s[pos.fs - 1][pos.sc] = 'S';
- pos.fs--;
- }
- }
- int main(){
- cin >> n >> m;
- string p;
- forn(i, 0, n){
- cin >> s[i];
- if (pos.fs == -1) forn(j, 0, m) if (s[i][j] == 'S') pos = mp(i, j), lst = mp(i, j);
- }
- forn(i, 0, n) forn(j, 0, m) a[i][j] = -1;
- cin >> p;
- forn(i, 0, p.sz()){
- if (!lost) move(p[i]);
- forn(i, 0, n){
- forn(j, 0, m)
- cerr << s[i][j];
- cerr << "\n";
- }
- cerr << "\n";
- }
- if (lost){
- printf("Epic Fail\n");
- return 0;
- }
- forn(i, 0, n){
- forn(j, 0, m)
- printf("%c", s[i][j]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement