#include using namespace std; struct Timer { using Clock = chrono::high_resolution_clock; chrono::time_point st{Clock::now()}; double elapsed() const { return chrono::duration(Clock::now() - st).count(); } }; constexpr int N = 10; constexpr int T = 1000; constexpr int choose = 6; constexpr int seed = 123456789; constexpr double TL = 1.98; int main() { int n_in, t_in; if (!(cin >> n_in >> t_in)) return 0; vector> A(N, vector(N, 0)); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cin >> A[i][j]; } } Timer timer; mt19937 rng(seed); uniform_int_distribution dist(0, N*N - 1); int best_score = -1; int iter = 0; vector best_combination, best_candidate_vals; while (timer.elapsed() < TL) { vector combination, candidate_vals; while (combination.size() < choose) { int idx = dist(rng); if (find(combination.begin(), combination.end(), idx) == combination.end()) { combination.emplace_back(idx); } } candidate_vals.emplace_back(0); for (int i = 0; i < choose; ++i) { candidate_vals.emplace_back(A[combination[i] / N][combination[i] % N] ^ candidate_vals.back()); } int score = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int val = A[i][j]; if (find(combination.begin(), combination.end(), i * N + j) == combination.end()) { for (int v : candidate_vals) { val = max(val, A[i][j] ^ v); } } score += val; } } if (score > best_score) { best_score = score; best_combination = combination; best_candidate_vals = candidate_vals; } iter++; } for (int idx : best_combination) { cerr << idx << ' ' << A[idx / N][idx % N] << endl; } cerr << "Best score: " << best_score << endl; cerr << "Iterations: " << iter << endl; vector> result(N, vector(N, -1)); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (find(best_combination.begin(), best_combination.end(), i * N + j) != best_combination.end()) { continue; } int val = -1; int idx = -1; for (int k = 0; k < choose + 1; ++k) { int candidate_val = A[i][j] ^ best_candidate_vals[k]; if (candidate_val > val) { val = candidate_val; idx = k; } } result[i][j] = idx; } } int score = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (result[i][j] == -1) { score += A[i][j]; } else { score += A[i][j] ^ best_candidate_vals[result[i][j]]; } } } cerr << "Final score: " << score << endl; vector output; output.reserve(1000); for (int i = 0; i < choose + 1; ++i) { for (int j = 0; j < N; ++j) { for (int k = 0; k < N; ++k) { int y = (j % 2 == 0) ? k : N - 1 - k; // jが偶数ならk, 奇数ならN-1-k if (result[j][y] == i) { output.emplace_back('W'); } if (k != N-1) { output.emplace_back(j % 2 ? 'L' : 'R'); } } if (j != N-1) { output.emplace_back('D'); } } if (i == choose) break; // 目標位置への移動 int target_x = best_combination[i] / N; int target_y = best_combination[i] % N; // X方向の移動 for (int j = N-1; j > target_x; --j) { output.emplace_back('U'); } // Y方向の移動 for (int j = 0; j < target_y; ++j) { output.emplace_back('R'); } output.emplace_back('C'); for (int j = target_y; j > 0; --j) { output.emplace_back('L'); } for (int j = target_x; j > 0; --j) { output.emplace_back('U'); } } for (char op : output) { cout << op << endl; } }