Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++;
	cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<int Modulo = MOD>
struct Mint {

	lint val;
	constexpr Mint(lint v = 0) noexcept : val(v % Modulo) { if (val < 0) val += Modulo; }

	constexpr Mint& operator += (const Mint &r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint &r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint &r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint &r) noexcept {
		lint a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			lint t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}

	constexpr Mint operator + (const Mint &r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint &r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint &r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint &r) const noexcept { return Mint(*this) /= r; }

	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }

	constexpr bool operator == (const Mint &r) const noexcept { return val == r.val; }
	constexpr bool operator != (const Mint &r) const noexcept { return val != r.val; }

	friend ostream &operator << (ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; }
	friend istream &operator >> (istream &is, Mint<Modulo> &x) noexcept {
		lint tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, lint n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	const int len = 200100;
    int N;
    string s;
    cin >> N >> s;
    for(auto &c: s) c = (c == 'W') + '0';
    mint ans = 0;

	auto dfs = [&](auto &&self, int now, bitset<len> used, bitset<len> s) -> void {

		if (now == -1) {
			for (int i = 0; i < 2 * N; i++) {
				if (!used[i]) {
					used[i].flip();
					self(self, i, used, s);
					return;
				}
			}
		}
		else {
			for (int i = 0; i < 2 * N; i++) {
				if (!used[i]) {
					auto tmp = used;
					tmp[i].flip();
					int l, r;
					tie(l, r) = minmax(i, now);

					auto t = new bitset<len>(string(len - 2 * N + l, '0') + string(r - l + 1, '1') + string(2 * N - r - 1, '0'));
					self(self, -1, tmp, s ^ t);
				}
			}
			return;
		}

		DMP(used);
		if (s == bitset<len>(string(len - 2 * N, '0') + string(2 * N, '1'))) ans+=1;

	};


	dfs(dfs, -1, bitset<len>(), bitset<len>(s));

	for (int i = 1; i <= N; i++) ans *= i;
	cout << ans << "\n";

	return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:134:63: error: no match for 'operator^' (operand types are 'std::bitset<200100>' and 'std::bitset<200100>*')
  134 |                                         self(self, -1, tmp, s ^ t);
      |                                                             ~ ^ ~
      |                                                             |   |
      |                                                             |   std::bitset<200100>*
      |                                                             std::bitset<200100>
In file included from a.cc:13:
/usr/include/c++/14/bitset:1577:5: note: candidate: 'template<long unsigned int _Nb> std::bitset<_Nb> std::operator^(const bitset<_Nb>&, const bitset<_Nb>&)'
 1577 |     operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
      |     ^~~~~~~~
/usr/include/c++/14/bitset:1577:5: note:   template argument deduction/substitution failed:
a.cc:134:65: note:   mismatched types 'const std::bitset<_Nb>' and 'std::bitset<200100>*'
  134 |                                         self(self, -1, tmp, s ^ t);
      |                                                                 ^
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/cstddef:146:3: note: candidate: 'constexpr std::byte std::operator^(byte, byte)'
  146 |   operator^(byte __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:146:18: note:   no known conversion for argument 1 from 'std::bitset<200100>' to 'std::byte'
  146 |   operator^(byte __l, byte __r) noexcept
      |             ~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:94:3: note: candidate: 'constexpr std::_Ios_Fmtflags std::operator^(_Ios_Fmtflags, _Ios_Fmtflags)'
   94 |   operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:94:27: note:   no known conversion for argument 1 from 'std::bitset<200100>' to 'std::_Ios_Fmtflags'
   94 |   operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:144:3: note: candidate: 'constexpr std::_Ios_Openmode std::operator^(_Ios_Openmode, _Ios_Openmode)'
  144 |   operator^(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:144:27: note:   no known conversion for argument 1 from 'std::bitset<200100>' to 'std::_Ios_Openmode'
  144 |   operator^(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:191:3: note: candidate: 'constexpr std::_Ios_Iostate std::operator^(_Ios_Iostate, _Ios_Iostate)'
  191 |   operator^(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:191:26: note:   no known conversion for argument 1 from 'std::bitset<200100>' to 'std::_Ios_Iostate'
  191 |   operator^(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~^~~