Advertisement
slash0t

Untitled

Feb 11th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <set>
  9. #include <vector>
  10. #include <map>
  11. #include <queue>
  12. #include <stack>
  13. #include <string>
  14. #include <cstring>
  15. #include <unordered_set>
  16. #include <unordered_map>
  17. #include <random>
  18. #include <chrono>
  19. #include <ctime>
  20. #include <complex>
  21. #include <bitset>
  22.  
  23. using namespace std;
  24.  
  25. #define int long long
  26. #define ld long double
  27. #define nl "\n"
  28. #define pb push_back
  29. #define xx first
  30. #define yy second
  31. #define cinn(a) for (int i = 0; i < (int) a.size(); i++) cin >> a[i];
  32. #define coutt(a) for (int i = 0; i < (int) a.size(); i++) cout << a[i] << (i == a.size() - 1 ? nl : " ");
  33. #define sortt(a) sort(a.begin(), a.end());
  34. #define rev(a) reverse(a.begin(), a.end());
  35. #define hi(a) (--a.end())
  36. #define lo(a) a.begin()
  37. #define ll(a) int a; cin >> a;
  38. #define vi(a, n) vector<int> a(n); cinn(a);
  39.  
  40. const int inf = 1e9 + 7;
  41. const int N = 2e5 + 69;
  42. const int M = 1e9 + 7;
  43.  
  44. bool vis[8][8];
  45. string s;
  46. map<char, pair<int, int>> mp;
  47. int res = 0;
  48.  
  49. void f(int x, int y, int step) {
  50. if (step == 48) {
  51. if (x == 0 && y == 6) res++;
  52. return;
  53. }
  54. if (s[step] == '?') {
  55. for (auto & p : mp) {
  56. int newx = x + p.yy.xx;
  57. int newy = y + p.yy.yy;
  58. if (newx < 0 || newx > 6 || newy < 0 || newy > 6 || vis[newx][newy]) continue;
  59. vis[newx][newy] = 1;
  60. f(newx, newy, step + 1);
  61. vis[newx][newy] = 0;
  62. }
  63. }
  64. else {
  65. auto& dir = mp[s[step]];
  66. int newx = x + dir.xx;
  67. int newy = y + dir.yy;
  68. if (!(newx < 0 || newx > 6 || newy < 0 || newy > 6 || vis[newx][newy])) {
  69. vis[newx][newy] = 1;
  70. f(newx, newy, step + 1);
  71. vis[newx][newy] = 0;
  72. }
  73. }
  74. }
  75.  
  76. void solve() {
  77. mp['D'] = {0, 1};
  78. mp['U'] = {0, -1};
  79. mp['R'] = {1, 0};
  80. mp['L'] = {-1, 0};
  81. cin >> s;
  82. vis[0][0] = 1;
  83. f(0, 0, 0);
  84. cout << res << nl;
  85. }
  86.  
  87. signed main()
  88. {
  89. //freopen("magic.in", "r", stdin);
  90. //freopen("magic.out", "w", stdout);
  91. #ifdef _DEBUG
  92. freopen("input.txt", "r", stdin);
  93. freopen("output.txt", "w", stdout);
  94. int start = chrono::high_resolution_clock::now().time_since_epoch().count();
  95. #endif
  96. ios_base::sync_with_stdio(0);
  97. cin.tie(0);
  98. cout.tie(0);
  99. cout << fixed;
  100. cout.precision(10);
  101.  
  102. int tests = 1;
  103. //cin >> tests;
  104. while (tests--) solve();
  105.  
  106. #ifdef _DEBUG
  107. cout << nl << "TIME ms: ";
  108. cout << (chrono::high_resolution_clock::now().time_since_epoch().count() - start) / 1e6 << nl;
  109. #endif
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement