Submission #5257766


Source Code Expand

Copy
#include<bits/stdc++.h>

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int H, W, N, Y, X;
  string S, T;
  cin >> H >> W >> N;
  cin >> Y >> X;
  --Y, --X;
  cin >> S >> T;
  const int d[] = {-1, 1, -1, 1};
  string V = "LRUD";
  for(int i = 0; i < 4; i++) {
    int pon = i <= 1 ? X : Y;
    int n = i <= 1 ? W : H;
    for(int j = 0; j < N; j++) {
      if(S[j] == V[i]) pon += d[j];
      if(pon < 0 || pon >= n) {
        cout << "NO" << endl;
        return 0;
      }
      if(T[j] == V[i ^ 1]) {
        pon -= d[j];
        if(pon < 0 || pon >= n) pon += d[j];
      }
    }
  }
  cout << "YES" << endl;
}


Submission Info

Submission Time
Task B - LRUD Game
User ei13333
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2328 Byte
Status
Exec Time 97 ms
Memory 920 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample01.txt, sample02.txt, sample03.txt
All 0 / 600 sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt 1 ms 256 KB
in02.txt 1 ms 256 KB
in03.txt 1 ms 256 KB
in04.txt 1 ms 256 KB
in05.txt 2 ms 912 KB
in06.txt 2 ms 920 KB
in07.txt 2 ms 592 KB
in08.txt 2 ms 848 KB
in09.txt 2 ms 920 KB
in10.txt 2 ms 592 KB
in11.txt 2 ms 792 KB
in12.txt 2 ms 720 KB
in13.txt 2 ms 792 KB
in14.txt 2 ms 848 KB
in15.txt 2 ms 792 KB
in16.txt 2 ms 848 KB
in17.txt 2 ms 720 KB
in18.txt 2 ms 848 KB
in19.txt 2 ms 720 KB
in20.txt 2 ms 720 KB
in21.txt 2 ms 720 KB
in22.txt 2 ms 592 KB
in23.txt 2 ms 720 KB
in24.txt 2 ms 720 KB
in25.txt 97 ms 720 KB
in26.txt 97 ms 848 KB
in27.txt 2 ms 848 KB
in28.txt 2 ms 720 KB
sample01.txt 1 ms 256 KB
sample02.txt 1 ms 256 KB
sample03.txt 1 ms 256 KB