結果
| 問題 |
No.5022 XOR Printer
|
| コンテスト | |
| ユーザー |
Shun_PI
|
| 提出日時 | 2025-07-26 13:34:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,960 bytes |
| コンパイル時間 | 3,012 ms |
| コンパイル使用メモリ | 193,752 KB |
| 実行使用メモリ | 7,716 KB |
| スコア | 5,165,750,483 |
| 最終ジャッジ日時 | 2025-07-26 13:34:40 |
| 合計ジャッジ時間 | 4,925 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
bool ok = true;
//そのビットより上のビットが全て立っているか確認
FOR(l, k+1, 20) {
if((A[i][j] & (1 << l)) == 0) {
ok = false;
break;
}
}
if(!ok) 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);
//そのビットが立っておらず、それより上のビットが全て立っているものを一つ残しておく
int last_x = -1, last_y = -1;
if(k < 19) {
IREP(i, N) IREP(j, N) {
if((A[i][j] & (1 << k)) == 0) {
bool ok = true;
FOR(l, k+1, 20) {
if((A[i][j] & (1 << l)) == 0) {
ok = false;
break;
}
}
if(!ok) continue;
last_x = i;
last_y = j;
break;
}
}
}
REP(i, N) {
if(i%2 == 0) {
REP(j, N) {
move(x, y, i, j, ans);
if((A[i][j] & (1 << k)) == 0) {
if(i == last_x && j == last_y) continue; //最後の1つは書き込まない
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(last_x != -1) {
move(x, y, last_x, last_y, ans);
copy(x, y, s, A, ans);
}
}
REP(i, min((int)ans.size(), 1000)) {
cout << ans[i] << "\n";
}
}
Shun_PI