結果
問題 |
No.5022 XOR Printer
|
ユーザー |
![]() |
提出日時 | 2025-07-25 16:14:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 2,010 bytes |
コンパイル時間 | 1,627 ms |
コンパイル使用メモリ | 137,140 KB |
実行使用メモリ | 7,720 KB |
スコア | 2,609,956,533 |
最終ジャッジ日時 | 2025-07-26 12:46:45 |
合計ジャッジ時間 | 3,610 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <random> #include <algorithm> using namespace std; int N, T; vector<vector<int>> A; int x = 0, y = 0, s = 0; vector<string> command_list = {"U", "D", "L", "R", "W", "C"}; // 移動可能かどうかを判定 bool can_move(int x, int y, const string& command) { if (command == "U") { return x > 0; } else if (command == "D") { return x < N - 1; } else if (command == "L") { return y > 0; } else if (command == "R") { return y < N - 1; } return true; } // コマンドを実行 void process_command(vector<vector<int>>& board, int& x, int& y, int& s, const string& command) { if (command == "U") { x = x - 1; } else if (command == "D") { x = x + 1; } else if (command == "L") { y = y - 1; } else if (command == "R") { y = y + 1; } else if (command == "W") { board[x][y] ^= s; } else if (command == "C") { s ^= board[x][y]; } } // スコアを計算 int calc_score(const vector<vector<int>>& board) { int score = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { score += board[i][j]; } } return score; } int main() { // 入力 cin >> N >> T; A.resize(N, vector<int>(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> A[i][j]; } } // 乱数生成器の初期化 random_device rd; mt19937 gen(rd()); uniform_int_distribution<> dis(0, command_list.size() - 1); // ランダムにコマンドを選択 vector<string> ans; while (ans.size() < T) { string command = command_list[dis(gen)]; if (can_move(x, y, command)) { process_command(A, x, y, s, command); ans.push_back(command); } } // 出力 for (int i = 0; i < T; i++) { cout << ans[i] << endl; } return 0; }