結果
| 問題 | No.5022 XOR Printer | 
| コンテスト | |
| ユーザー |  Shun_PI | 
| 提出日時 | 2025-07-26 13:26:35 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 3,099 bytes | 
| コンパイル時間 | 2,698 ms | 
| コンパイル使用メモリ | 194,464 KB | 
| 実行使用メモリ | 7,716 KB | 
| スコア | 4,575,659,115 | 
| 最終ジャッジ日時 | 2025-07-26 13:26:41 | 
| 合計ジャッジ時間 | 5,364 ms | 
| ジャッジサーバーID (参考情報) | judge6 / judge2 | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 50 | 
ソースコード
#include <string>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);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<lint> RH_B = {1532834020, 1388622299};
vector<lint> RH_M = {2147482409, 2147478017};
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
vector<char> dc = {'U', 'L', 'D', 'R'};
void move(int &x, int &y, int tx, int ty, vector<char> &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<vector<int>> &A, vector<char> &ans) {
  s ^= A[x][y];
  ans.push_back('C');
}
void write(int x, int y, int &s, vector<vector<int>> &A, vector<char> &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<vector<int>> A(N, vector<int>(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<char> 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";
  }
}
            
            
            
        