QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#836744#9926. Flipping Pathsucup-team3695#WA 0ms3836kbC++201.6kb2024-12-29 05:07:502024-12-29 05:07:55

Judging History

你现在查看的是最新测评结果

  • [2024-12-29 05:07:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-12-29 05:07:50]
  • 提交

answer

#include <bits/extc++.h>

using namespace std;
namespace rg = ranges;
namespace vw = views;

static inline void go(size_t), pre();

static constexpr size_t MN = 200, MK = 2 * MN - 1;

static bitset<MN> G[MN];
static bitset<MK> P;
static size_t	  n, m, k;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	size_t T;
	cin >> T;
	for (size_t i = 0; i < T; i++)
		go(i);
}

void pre() {}

void go(size_t)
{
	cin >> n >> m;
	k = n + m - 1;
	P.reset();

	for (size_t i = 0; i < n; i++)
		for (size_t j = 0, u = i; j < m; j++, u++)
		{
			char c;
			cin >> c;
			bool g	= (c == 'W');
			G[i][j] = g;
			P[u]	= P[u] ^ g;
		}

	bool odd = P[0];

	if (!(odd ? P.all() : P.none()))
	{
		odd = !odd;
		for (size_t i = 0; i < n; i++)
			for (size_t j = 0, u = i, v = m - 1 + i; j < m; j++, u++, v--)
			{
				G[i].flip(j);
				P.flip(u);
			}
	}

	if (!(odd ? P.all() : P.none()))
	{
		cout << "NO\n";
		return;
	}
	cout << "YES\n" << k + odd << '\n';

	for (size_t ai = 0; ai < k - 1; ai++)
	{
		size_t i = 0, j = 0, v = m - 1;
		G[0].flip(0);
		auto const R = [&]()
		{
			cout << 'R';
			j++;
			v--;
			G[i].flip(j);
		};
		auto const D = [&]()
		{
			cout << 'D';
			i++;
			v++;
			G[i].flip(j);
		};

		while (v > ai + 1)
			R();
		while (v < ai + 1)
			D();

		while (i < n - 1 & j < m - 1)
		{
			if (G[i][j + 1])
			{
				R();
				D();
			}
			else
			{
				D();
				R();
			}
		}
		while (i < n - 1)
			D();
		while (j < m - 1)
			R();
		cout << '\n';
	}
	if (odd)
	{
		cout << string('D', n - 1) << string('R', m - 1) << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3836kb

input:

4
3 3
WBB
BWB
BBW
1 5
WWWWW
2 2
BB
BB
4 1
W
B
B
W

output:

YES
5
RRDD
DRDR
DRDR
DDRR
YES
5
RRRR
RRRR
RRRR
RRRR
YES
3
DR
DR
NO

result:

wrong answer Line "YES" doesn't correspond to pattern "[RD]{4}" (test case 1)