#include using namespace std; using ll = long long; // ===== XOR Basis (20-bit) ===== struct XorBasis { static const int B = 20; int v[B]; bitset<128> used[B]; XorBasis(){ memset(v,0,sizeof(v)); } void add(int x, const bitset<128>& bs){ bitset<128> c = bs; for(int b=B-1;b>=0;--b){ if(((x>>b)&1)==0) continue; if(v[b]==0){ v[b]=x; used[b]=c; return; } x ^= v[b]; c ^= used[b]; } } pair> build(int target) const { int t = target, made = 0; bitset<128> sel; sel.reset(); for(int b=B-1;b>=0;--b){ if(((t>>b)&1)==0) continue; if(v[b]==0) continue; // cannot set that bit t ^= v[b]; made ^= v[b]; sel ^= used[b]; } return {made, sel}; } }; static inline long long eval_score(const vector& A, int s){ long long sum = 0; for(int x: A){ int y = x ^ s; sum += (y > x ? y : x); } return sum; } static inline void move_to(int &r,int &c,int tr,int tc, vector& ops){ while(rtr){ ops.push_back('U'); --r; } while(ctc){ ops.push_back('L'); --c; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,T; if(!(cin>>N>>T)) return 0; // N=10, T=1000 vector> A2(N, vector(N)); for(int i=0;i>A2[i][j]; // flatten vector flatA(N*N); for(int i=0;i>b)&1) cnt1++; else cnt0++; } if(cnt0 > cnt1) s1_target |= (1< bs; bs.reset(); bs.set(i*N + j); basis.add(A2[i][j], bs); } auto [s0_real, cells0] = basis.build(s0); auto [s1_real, cells1] = basis.build(s1_target); int bestS = s0_real; bitset<128> bestC = cells0; long long bestScore = eval_score(flatA, bestS); { long long sc1 = eval_score(flatA, s1_real); if(sc1 > bestScore){ bestScore=sc1; bestS=s1_real; bestC=cells1; } } // --- exhaustive search over all 2^20 s --- // keep non-decreasing guarantee: only replace when strictly better const int LIMIT = 1<<20; // 1,048,576 for(int s=0; s bestScore){ bestScore = sc; bestS = s; } } // map bestS to achievable S_real via basis auto [S_real, cells_final] = basis.build(bestS); if(S_real != bestS){ long long sc_real = eval_score(flatA, S_real); if(sc_real >= bestScore){ bestScore=sc_real; bestS=S_real; bestC=cells_final; } // else keep previous bestS; but we still need some C set. Build again from that bestS just in case else { bestC = cells_final; } }else{ bestC = cells_final; } // ---- construct ops ---- vector ops; int r=0,c=0; vector> snake; snake.reserve(N*N); for(int i=0;i=0;j--) snake.emplace_back(i,j); } if(!snake.empty()){ move_to(r,c, snake[0].first, snake[0].second, ops); for(size_t k=0;k0) move_to(r,c, rr, cc, ops); int x = A2[rr][cc]; if( (x ^ bestS) > x ) ops.push_back('W'); } } if((int)ops.size() > T) ops.resize(T); // unlikely for(char ch: ops) cout << ch << '\n'; return 0; }