#line 1 "main.cpp" #include using namespace std; #line 6 "/home/hidehic0/src/github.com/hidehic0/library_cpp/templates/alias.hpp" using ll = long long; using ld = long double; using vi = std::vector; using vvi = std::vector>; using si = std::set; using mii = std::map; template using V = std::vector; const std::string upperlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const std::string lowerlist = "abcdefghijklmnopqrstuvwxyz"; #define mp make_pair #define dms << " " << #line 3 "/home/hidehic0/src/github.com/hidehic0/library_cpp/templates/macro.hpp" #define rep(i, n) for (ll i = 0; i < (int)(n); i++) #define REP(i, a, b) for (ll i = (int)(a); i < (int)(b); ++i) #define all(a) (a).begin(), (a).end() template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } void YN(bool b) { std::cout << (b ? "Yes" : "No") << std::endl; } void YE(bool b) { if (b) { std::cout << "Yes" << std::endl; exit(1); } } void NE(bool b) { if (b) { std::cout << "No" << std::endl; exit(1); } } #line 8 "main.cpp" ll N, T; unsigned long long randint() { static unsigned long long x = 88172645463325252LL; x ^= (x << 13); x ^= (x >> 7); return (x ^= (x << 17)); } ll randrange(ll a, ll b) { return a + randint() % (b - a + 1); } ll getscore(vector> A, vector> L) { ll res = 0, t = 0; for (auto [i, k] : L) { t += (i + k) * 2; t += 180; rep(x, N) { rep(y, N) { if (find(all(L), make_pair(x, y)) == L.end()) { if (A[x][y] < (A[x][y] ^ A[i][k])) { t++; A[x][y] ^= A[i][k]; } } } } } rep(x, N) { rep(y, N) { res += A[x][y]; } } if (t > 1000) { return 0; } return res; } vector get_output(vector> A, vector> L) { vector res; for (auto [i, k] : L) { rep(_, i) { res.emplace_back("R"); } rep(_, k) { res.emplace_back("D"); } res.emplace_back("W"); rep(_, i) { res.emplace_back("L"); } rep(_, k) { res.emplace_back("U"); } bool f = false; rep(x, N) { ll y = f ? N - 1 : 0; while (0 <= y && y < N) { if (find(all(L), make_pair(x, y)) == L.end() && A[x][y] < (A[i][k] ^ A[x][y])) { A[i][k] ^= A[x][y]; res.emplace_back("W"); } if ((f && y != 0) || (!f && y != 9)) { res.emplace_back(f ? "L" : "R"); } y += f ? -1 : 1; } f ^= 1; if (x != N - 1) { res.emplace_back("D"); } } rep(_, 9) { res.emplace_back("U"); } } return res; } int main() { cin >> N >> T; vector> A(N, vector(N)); rep(i, N) { rep(k, N) { cin >> A[i][k]; } } vector> CL; ll _sc = getscore(A, CL); rep(i, N) { rep(k, N) { ll _nc = getscore(A, {make_pair(i, k)}); if (_sc < _nc) { CL = {make_pair(i, k)}; _sc = _nc; } } } ll Q = 100000; while (Q--) { ll type = randrange(0, 1); type = CL.size() == 0 ? 0 : type; if (type == 0) { ll i = randrange(0, N - 1); ll k = randrange(0, N - 1); while (find(all(CL), make_pair(i, k)) != CL.end()) { i = randrange(0, N - 1); k = randrange(0, N - 1); } CL.push_back(make_pair(i, k)); ll _nc = getscore(A, CL); if (_sc < _nc) { _sc = _nc; } else { CL.pop_back(); } } else { ll pi = randrange(0, CL.size() - 1); auto [px, py] = CL[pi]; CL.erase(CL.begin() + pi); ll i = randrange(0, N - 1); ll k = randrange(0, N - 1); while (find(all(CL), make_pair(i, k)) != CL.end()) { i = randrange(0, N - 1); k = randrange(0, N - 1); } CL.push_back(make_pair(i, k)); ll _nc = getscore(A, CL); if (_sc < _nc) { _sc = _nc; } else { CL.pop_back(); CL.insert(CL.begin() + pi, make_pair(px, py)); } } } for (auto s : get_output(A, CL)) { cout << s << "\n"; } }