Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <fstream>
- #include <set>
- #include <vector>
- #include <map>
- #include <queue>
- #include <stack>
- #include <string>
- #include <cstring>
- #include <unordered_set>
- #include <unordered_map>
- #include <random>
- #include <chrono>
- #include <ctime>
- #include <complex>
- #include <bitset>
- using namespace std;
- #define int long long
- #define ld long double
- #define nl "\n"
- #define pb push_back
- #define xx first
- #define yy second
- #define cinn(a) for (int i = 0; i < (int) a.size(); i++) cin >> a[i];
- #define coutt(a) for (int i = 0; i < (int) a.size(); i++) cout << a[i] << (i == a.size() - 1 ? nl : " ");
- #define sortt(a) sort(a.begin(), a.end());
- #define rev(a) reverse(a.begin(), a.end());
- #define hi(a) (--a.end())
- #define lo(a) a.begin()
- #define ll(a) int a; cin >> a;
- #define vi(a, n) vector<int> a(n); cinn(a);
- const int inf = 1e9 + 7;
- const int N = 2e5 + 69;
- const int M = 1e9 + 7;
- bool vis[8][8];
- string s;
- map<char, pair<int, int>> mp;
- int res = 0;
- void f(int x, int y, int step) {
- if (step == 48) {
- if (x == 0 && y == 6) res++;
- return;
- }
- if (s[step] == '?') {
- for (auto & p : mp) {
- int newx = x + p.yy.xx;
- int newy = y + p.yy.yy;
- if (newx < 0 || newx > 6 || newy < 0 || newy > 6 || vis[newx][newy]) continue;
- vis[newx][newy] = 1;
- f(newx, newy, step + 1);
- vis[newx][newy] = 0;
- }
- }
- else {
- auto& dir = mp[s[step]];
- int newx = x + dir.xx;
- int newy = y + dir.yy;
- if (!(newx < 0 || newx > 6 || newy < 0 || newy > 6 || vis[newx][newy])) {
- vis[newx][newy] = 1;
- f(newx, newy, step + 1);
- vis[newx][newy] = 0;
- }
- }
- }
- void solve() {
- mp['D'] = {0, 1};
- mp['U'] = {0, -1};
- mp['R'] = {1, 0};
- mp['L'] = {-1, 0};
- cin >> s;
- vis[0][0] = 1;
- f(0, 0, 0);
- cout << res << nl;
- }
- signed main()
- {
- //freopen("magic.in", "r", stdin);
- //freopen("magic.out", "w", stdout);
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int start = chrono::high_resolution_clock::now().time_since_epoch().count();
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed;
- cout.precision(10);
- int tests = 1;
- //cin >> tests;
- while (tests--) solve();
- #ifdef _DEBUG
- cout << nl << "TIME ms: ";
- cout << (chrono::high_resolution_clock::now().time_since_epoch().count() - start) / 1e6 << nl;
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement