fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define int long long
  4. using namespace std;
  5. const int maxn = 1e6+7;
  6. ll n,m,ans=1,pre[maxn],a,b;
  7. map<pair<ll,ll>,ll> mp;
  8. int32_t main()
  9. {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12. freopen("ROBOT.INP","r",stdin);
  13. freopen("ROBOT.OUT","w",stdout);
  14. cin >> n >> m;
  15. string s,t; cin >> s >> t;
  16. ll x=1,y=1;
  17. mp[{x,y}] = 1;
  18. mp[{n,m}] = 1;
  19. for (auto c:s)
  20. {
  21. if (c == 'D')
  22. {
  23. x++;
  24. mp[{x,y}] = 1;
  25. }
  26. else if (c == 'R')
  27. {
  28. y++;
  29. mp[{x,y}] = 1;
  30. }
  31. }
  32. x = n, y = m;
  33. for (auto c:t)
  34. {
  35. if (c == 'U')
  36. {
  37. x--;
  38. if (mp[{x,y}] == 1) ans++;
  39. }
  40. else if (c == 'L')
  41. {
  42. y--;
  43. if (mp[{x,y}] == 1) ans++;
  44. }
  45. // cout << ans << '\n';
  46. }
  47.  
  48. cout << ans;
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty