Language: C++

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

struct Dice {
	int tp;
	int bo;
	int no;
	int so;
	int ea;
	int we;
	Dice(const int tp_, const int bo_, const int no_, const int so_, const int ea_, const int we_) :
		tp(tp_), bo(bo_), no(no_), so(so_), ea(ea_), we(we_) {
	}
	Dice(vector<int>pips_) {

	}
	Dice() {
		tp = 1;
		/*bo = 6;
		no = 2;
		so = 5;
		ea = 3;
		we = 4;*/
	}
	enum R_Way {
		R_Left=0,
		R_Front=1,
		R_Right=2,
		R_Back=3,

		R_Dummy,
	};
	int rotate(const R_Way way) {
		switch (way) {
		case R_Right: {
			int c = tp;
			tp = we;
			we = bo;
			bo = ea;
			ea = c;
		}
					  break;
		case R_Back: {
			int c = tp;
			tp = so;
			so = bo;
			bo = no;
			no = c;
		}
					 break;
		case R_Left: {
			int c = tp;
			tp = ea;
			ea = bo;
			bo = we;
			we = c;
		}
					 break;
		case R_Front: {
			int c = tp;
			tp = no;
			no = bo;
			bo = so;
			so = c;
		}
					  break;
		default:
			assert(false);
		}
		return tp;
	}
	int rotate(const int way) {
		return rotate(static_cast<R_Way>(way));
	}
	int hash()const {
		return tp + we * 6 + no * 36;
	}
};
int geteast(int top, int south) {
	map<pair<int, int>, int>mp;
	mp[make_pair(1, 2)] = 3;
	mp[make_pair(1, 3)] = 5;
	mp[make_pair(2, 3)] = 1;
	mp[make_pair(2, 4)] = 6;
	bool rev = false;
	if (top >= 4) {
		rev = !rev; top = 7 - top;
	}
	if (south >= 4) {
		rev = !rev; south = 7 - south;
	}
	if (top > south) {
		rev = !rev; swap(top, south);
	}
	return mp[make_pair(top, south)];
}

int gettop(int south, int east) {
	return geteast(south, east);
}
int getsouth(int east, int top) {
	return 7 - geteast(top, east);
}
bool operator==(const Dice&l, const Dice&r) {
	return l.hash() == r.hash();
}


const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

pair<int,map<pair<short, short>, int>>getmemo(const vector<map<pair<short, short>, short>>&field,vector<pair<int,map<pair<short, short>, short>>>&memo,bitset<15>&used) {
	if (memo[used.to_ulong()].second.empty()) {
		if (!used.count()) {
			return make_pair(0,map < pair<short, short>, short> ());
		}
		else {
			int high_sc = -1;
			map<pair<int, int>, int>hi_fi;
			for (int i = 0; i < 15; ++i) {
				if (used[i]) {
					used[i] = false;
					auto pre(getmemo(field,memo, used));
					 int sc = pre.first;
					auto pre_fi = pre.second;
					used[i] = true;
					for (auto n_c : field[i]) {
						if (pre_fi.find(n_c.first) == pre_fi.end()) {
							pre_fi[n_c.first] = n_c.second;
							sc += n_c.second;
						}
					}
					if (high_sc < sc) {
						high_sc = sc;
						hi_fi = pre_fi;
					}
				}
			}
			return memo[used.to_ulong()]=make_pair(high_sc, hi_fi);
		}
	}
	else {
		return memo[used.to_ulong()];
	}
}
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<map<pair<short, short>, short>>field(N, map<pair<short, short>, short>());
		map<char, short>name;
		name['R'] = 2;
		name['L'] = 0;
		name['B'] = 3;
		name['F'] = 1;
		for (int i = 0; i < N; ++i) {
			map<pair<short, short>, short>mp;
			int x, y; cin >> x >> y;
			int l, r, f, b, d, u; cin >> l >> r >> f >> b >> d >> u;
			string rot; cin >> rot;
			mp[make_pair(x, y)] = d;
			Dice di(u, d, b, f, r, l);

			for (auto c : rot) {
				const int way = name[c];
				x += dx[way];
				y += dy[way];
				di.rotate(way);
				mp[make_pair(x, y)] = di.bo;
			}
			field[i] = mp;
		}
		vector<pair<int,map<pair<short, short>, short>>>memo(1<<N);
		bitset<15>bs((1 << N) - 1);
		auto ans = getmemo(field, memo, bs);
		cout << ans.first << endl;
		
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'std::pair<int, std::map<std::pair<short int, short int>, int> > getmemo(const std::vector<std::map<std::pair<short int, short int>, short int> >&, std::vector<std::pair<int, std::map<std::pair<short int, short int>, short int> > >&, std::bitset<15>&)':
a.cc:122:41: error: could not convert 'std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = map<pair<short int, short int>, short int>; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = map<pair<short int, short int>, short int>; typename decay<_Tp2>::type = map<pair<short int, short int>, short int>](std::map<std::pair<short int, short int>, short int>())' from 'pair<[...],map<[...],short int>>' to 'pair<[...],map<[...],int>>'
  122 |                         return make_pair(0,map < pair<short, short>, short> ());
      |                                ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                         |
      |                                         pair<[...],map<[...],short int>>
a.cc:142:57: error: no match for 'operator=' (operand types are 'std::map<std::pair<int, int>, int>' and 'std::map<std::pair<short int, short int>, int>')
  142 |                                                 hi_fi = pre_fi;
      |                                                         ^~~~~~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:331:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
  331 |       operator=(const map&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:331:17: note:   no known conversion for argument 1 from 'std::map<std::pair<short int, short int>, int>' to 'const std::map<std::pair<int, int>, int>&'
  331 |       operator=(const map&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:335:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::map<_Key, _Tp, _Compare, _Alloc>&&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
  335 |       operator=(map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:335:17: note:   no known conversion for argument 1 from 'std::map<std::pair<short int, short int>, int>' to 'std::map<std::pair<int, int>, int>&&'
  335 |       operator=(map&&) = default;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_map.h:349:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::initializer_list<std::pair<const _Key, _Val> >) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
  349 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:349:46: note:   no known conversion for argument 1 from 'std::map<std::pair<short int, short int>, int>' to 'std::initializer_list<std::pair<const std::pair<int, int>, int> >'
  349 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:146:78: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::map<std::pair<short int, short int>, short int> > >, std::pair<int, std::map<std::pair<short int, short int>, short int> > >::value_type' {aka 'std::pair<int, std::map<std::pair<short int, short int>, short int> >'} and 'std::pair<int, std::map<std::pair<int, int>, int> >')
  146 |                         return memo[used.to_ulong()]=make_pair(high_sc, hi_fi);
      |                                                                              ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int; _T2 = std::map<std::pair<short int, short int>, short int>]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, const _U1&>, std::is_assignable<std::map<std::pair<short int, short int>, short int, std::less<std::pair<short int, short int> >, std::allocator<std::pair<const std::pair<short int, short int>, short int> > >&, const _U2&> >::value, std::pair<int, std::map<std::pair<short int, short int>, short int> >&>::type std::pair<int, std::map<std::pair<short int, short int>, short int> >::operator=(const std::pair<_T1, _T2>&) [with _U1 = int; _U2 = std::map<std::pair<int, int>, int>]':
a.cc:146:57:   required from here
  146 |                         return memo[used.to_ulong()]=make_pair(high_sc, hi_fi);
      |                                                                              ^
/usr/include/c++/14/bits/stl_pair.h:946:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::map<std::pair<short int, short int>, short int> >&>'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int; _T2 = std::map<std::pair<short int, short int>, short int>]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h: In substitution of 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<int&, _U1&&>, std::is_assignable<std::map<std::pair<short int, short int>, short int, std::less<std::pair<short int, short int> >, std::allocator<std::pair<const std::pair<short int, short int>, short int> > >&, _U2&&> >::value, std::pair<int, std::map<std::pair<short int, short int>, short int> >&>::type std::pair<int, std::map<std::pair<short int, short int>, short int> >::operator=(std::pair<_T1, _T2>&&) [with _U1 = int; _U2 = std::map<std::pair<int, int>, int>]':
a.cc:146:57:   required from here
  146 |                         return memo[used.to_ulong()]=make_pair(high_sc, hi_fi);
      |                                                                              ^
/usr/include/c++/14/bits/stl_pair.h:957:9: error: no type named 'type' in 'struct std::enable_if<false, std::pair<int, std::map<std::pair<short int, short int>, short int> >&>'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = int; _T2 = std::map<std::pair<short int, short int>, short int>; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<int, std::map<std::pair<short int, short int>, short int> >&]'
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:923:65: note:   no known conversion for argument 1 from 'std::pair<int, std::map<std::pair<int, int>, int> >' to 'std::__conditional_t<true, const std::pair<int, std::map<std::pair<short int, short int>, short int> >&, const std::__nonesuch&>' {aka 'const std::pair<int, std::map<std::pair<short int, short int>, short int> >&'}
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  922 |                                        is_copy_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923 |                                 const pair&, const __nonesuch&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = std::map<std::pair<short int, short int>, short int>; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<int, std::map<std::pair<short int, short int>, short int> >&&]'
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:933:55: note:   no known conversion for argument 1 from 'std::pair<int, std::map<std::pair<int, int>, int> >' to 'std::__conditional_t<true, std::pair<int, std::map<std::pair<short int, short int>, short int> >&&, std::__nonesuch&&>' {aka 's