Advertisement
PikMike

Untitled

Dec 26th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define sz size
  6. #define ll long long
  7. #define ld long double
  8. #define fs first
  9. #define sc second
  10. #define forn(i, f, t) for(int i = f; i < t; i++)
  11. #define all(x) (x).begin(), (x).end()
  12. #define ins insert
  13.  
  14. const int INF = 2147483647;
  15. const int MOD = 1000000007;
  16. const ll INF64 = 9223372036854775807;
  17. const ld EPS = 1e-7;
  18.  
  19. using namespace std;
  20.  
  21. pair<int, int> pos = mp(-1, -1), lst;
  22. int a[21][21], n, m;
  23. bool lost = 0, ap = 0;
  24. string s[21];
  25.  
  26.  
  27. pair<int, int> getNext(pair<int, int> p){
  28.     switch (a[p.fs][p.sc]){
  29.         case 0: return mp(p.fs - 1, p.sc);
  30.         case 1: return mp(p.fs, p.sc + 1);
  31.         case 2: return mp(p.fs + 1, p.sc);
  32.         case 3: return mp(p.fs, p.sc - 1);
  33.     }
  34. }
  35.  
  36.  
  37. void move(char c){
  38.     if (c == 'L' && pos.sc == 0){lost = 1; return;}
  39.     else if (c == 'L'){
  40.         if (s[pos.fs][pos.sc - 1] == 'S'){lost = 1; return;}
  41.         a[pos.fs][pos.sc] = 3;
  42.         if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
  43.         if (s[pos.fs][pos.sc - 1] == 'A') ap = 1;
  44.         else ap = 0;
  45.         s[pos.fs][pos.sc - 1] = 'S';
  46.         pos.sc--;
  47.     }
  48.     if (c == 'D' && pos.fs == n - 1){lost = 1; return;}
  49.     else if (c == 'D'){
  50.         if (s[pos.fs + 1][pos.sc] == 'S'){lost = 1; return;}
  51.         a[pos.fs][pos.sc] = 2;
  52.         if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
  53.         if (s[pos.fs + 1][pos.sc] == 'A') ap = 1;
  54.         else ap = 0;
  55.         s[pos.fs + 1][pos.sc] = 'S';
  56.         pos.fs++;
  57.     }
  58.     if (c == 'R' && pos.sc == m - 1){lost = 1; return;}
  59.     else if (c == 'R'){
  60.         if (s[pos.fs][pos.sc + 1] == 'S'){lost = 1; return;}
  61.         a[pos.fs][pos.sc] = 1;
  62.         if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
  63.         if (s[pos.fs][pos.sc + 1] == 'A') ap = 1;
  64.         else ap = 0;
  65.         s[pos.fs][pos.sc + 1] = 'S';
  66.         pos.sc++;
  67.     }
  68.     if (c == 'U' && pos.fs == 0){lost = 1; return;}
  69.     else if (c == 'U'){
  70.         if (s[pos.fs - 1][pos.sc] == 'S'){lost = 1; return;}
  71.         a[pos.fs][pos.sc] = 0;
  72.         if (!ap) s[lst.fs][lst.sc] = '.', lst = getNext(lst);
  73.         if (s[pos.fs - 1][pos.sc] == 'A') ap = 1;
  74.         else ap = 0;
  75.         s[pos.fs - 1][pos.sc] = 'S';
  76.         pos.fs--;
  77.     }
  78. }
  79.  
  80.  
  81. int main(){
  82.     cin >> n >> m;
  83.     string p;
  84.     forn(i, 0, n){
  85.         cin >> s[i];
  86.         if (pos.fs == -1) forn(j, 0, m) if (s[i][j] == 'S') pos = mp(i, j), lst = mp(i, j);
  87.     }
  88.     forn(i, 0, n) forn(j, 0, m) a[i][j] = -1;
  89.     cin >> p;
  90.     forn(i, 0, p.sz()){
  91.         if (!lost) move(p[i]);
  92.         forn(i, 0, n){
  93.             forn(j, 0, m)
  94.                 cerr << s[i][j];
  95.             cerr << "\n";
  96.         }
  97.         cerr << "\n";
  98.     }
  99.     if (lost){
  100.         printf("Epic Fail\n");
  101.         return 0;
  102.     }
  103.     forn(i, 0, n){
  104.         forn(j, 0, m)
  105.             printf("%c", s[i][j]);
  106.         printf("\n");
  107.     }
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement