#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using lint = long long int; using P = pair; using PL = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; vector RH_B = {1532834020, 1388622299}; vector RH_M = {2147482409, 2147478017}; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} templatevoid chmax(T &a, const T &b) { if (avoid chmin(T &a, const T &b) { if (b dx = {-1, 0, 1, 0}; vector dy = {0, -1, 0, 1}; vector dc = {'U', 'L', 'D', 'R'}; void move(int &x, int &y, int tx, int ty, vector &ans) { if (x < tx) { REP(i, tx - x) ans.push_back('D'); } else { REP(i, x - tx) ans.push_back('U'); } if (y < ty) { REP(i, ty - y) ans.push_back('R'); } else { REP(i, y - ty) ans.push_back('L'); } x = tx; y = ty; } void copy(int x, int y, int &s, vector> &A, vector &ans) { s ^= A[x][y]; ans.push_back('C'); } void write(int x, int y, int &s, vector> &A, vector &ans) { A[x][y] ^= s; ans.push_back('W'); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, T; cin >> N >> T; vector> A(N, vector(N)); REP(i, N) { REP(j, N) { cin >> A[i][j]; } } //上位のビットから以下をする //1. sにそのビットが立っており、それより上のビットが立っていない状態にする //2. 各マスについてビットが立っていなければ書き込むをする //ただし、1つはそのビットが立っていないマスを残さないと次のビットに進めない int x = 0; int y = 0; int s = 0; vector ans; int turn = 0; IREP(k, 20) { //sについてそのビットを立てる int min_dist = INF; int tx = 0, ty = 0; REP(i, N) REP(j, N) { if((A[i][j] & (1 << k)) == (s & (1 << k))) continue; if(k < 19 && (A[i][j] & (1 << (k + 1))) != (s & (1 << (k + 1)))) continue; if (abs(x - i) + abs(y - j) < min_dist) { min_dist = abs(x - i) + abs(y - j); tx = i; ty = j; } } move(x, y, tx, ty, ans); copy(tx, ty, s, A, ans); move(x, y, 0, 0, ans); REP(i, N) { if(i%2 == 0) { REP(j, N) { move(x, y, i, j, ans); if((A[i][j] & (1 << k)) == 0) { write(i, j, s, A, ans); } } } else { IREP(j, N) { move(x, y, i, j, ans); if((A[i][j] & (1 << k)) == 0) { write(i, j, s, A, ans); } } } } if(k == 18)break; } REP(i, min((int)ans.size(), 1000)) { cout << ans[i] << "\n"; } }