結果
問題 |
No.5022 XOR Printer
|
ユーザー |
|
提出日時 | 2025-07-26 13:58:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,954 ms / 2,000 ms |
コード長 | 3,403 bytes |
コンパイル時間 | 3,191 ms |
コンパイル使用メモリ | 291,588 KB |
実行使用メモリ | 7,716 KB |
スコア | 2,642,685,024 |
最終ジャッジ日時 | 2025-07-26 13:59:51 |
合計ジャッジ時間 | 105,297 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct Timer { using Clock = chrono::high_resolution_clock; chrono::time_point<Clock> st{Clock::now()}; double elapsed() const { return chrono::duration<double>(Clock::now() - st).count(); } }; constexpr int N = 10; constexpr int T = 1000; constexpr int choose = 6; constexpr int seed = 123456789; constexpr double TL = 1.95; int main() { int n_in, t_in; if (!(cin >> n_in >> t_in)) return 0; vector<vector<int>> 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<int> dist(0, N*N - 1); int best_score = -1; vector<int> best_combination, best_candidate_vals; while (timer.elapsed() < TL) { vector<int> 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]; 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; } } cerr << "Best score: " << best_score << endl; vector<vector<int>> result(N, vector(N, 0)); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { int val = -1; int idx = -1; for (int k = 0; k < choose + 1; ++k) { if (val < A[i][j] ^ best_candidate_vals[k]) { val = A[i][j] ^ best_candidate_vals[k]; idx = k; } } result[i][j] = idx; } } vector<char> 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) { if (result[j][k] == i && i != 0) { 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 x = best_combination[i] / N; int y = best_combination[i] % N; for (int j = x; j < N-1; ++j) { output.emplace_back('U'); } for (int j = 0; j < y; ++j) { output.emplace_back('R'); } output.emplace_back('C'); for (int j = 0; j < x; ++j) { output.emplace_back('U'); } for (int j = 0; j < y; ++j) { output.emplace_back('L'); } } for (char c : output) { cout << c << endl; } }