QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#834463#9926. Flipping Pathsyyf_0404#WA 1ms4000kbC++171.6kb2024-12-27 17:44:042024-12-27 17:44:04

Judging History

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

  • [2024-12-27 17:44:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4000kb
  • [2024-12-27 17:44:04]
  • 提交

answer

// l.cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[205][205];
int cnt[405][2], to;
void solve() {
    cin >> n >> m;
    memset(cnt, 0, n + m << 3);
    for (int i = 0; i < n; i++) {
    	cin >> s[i];
    	for (int j = 0; j < m; j++) {
    		cnt[i + j][s[i][j] == 'W'] += 1;
    	}
    }
    to = 3;
    for (int i = 1; i < n + m - 1; i++) {
    	if (cnt[i][0] + cnt[0][0] & 1) {
    		to &= 2;
    	}
    	if (cnt[i][1] + cnt[0][1] & 1) {
    		to &= 1;
    	}
    }
    if (to == 0) {
    	printf("NO\n");
    	return;
    }
    if (to == 3) {
    	printf("YES\n0\n");
    	return;
    }
    to = __lg(to);
    vector<string> ans;
    for (int u = 0; u < n + m - 1; u++) {
    	vector<pair<int, int> > q;
    	for (int i = max(0, u - m + 1); i <= u && i < n; i++) {
    		int j = i - u + m - 1;
    		if ((i == n - 1) + (j == 0) != 1 && (s[i][j] == 'W') == to) {
    			q.push_back({i, j});
    		}
    	}
    	if (q.empty()) {
    		continue;
    	}
    	q.push_back({n - 1, m - 1});
    	string S;
    	int x = 0, y = 0;
    	s[x][y] ^= 'B' ^ 'W';
    	for (auto [i, j] : q) {
    		while (x < i) {
    			x += 1;
    			S += 'D';
    			s[x][y] ^= 'B' ^ 'W';
    		}
    		while (y < j) {
    			y += 1;
    			S += 'R';
    			s[x][y] ^= 'B' ^ 'W';
    		}
    	}
    	ans.push_back(S);
    }
    cout << "YES\n" << ans.size() << "\n";
    for (string &s : ans)
    	cout << s << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3996kb

input:

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

output:

YES
2
RRDD
DDRR
YES
0
YES
0
NO

result:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4000kb

input:

323
1 2
BB
1 2
BW
1 2
WB
1 2
WW
2 1
B
B
2 1
B
W
2 1
W
B
2 1
W
W
1 3
BBB
1 3
BBW
1 3
BWB
1 3
BWW
1 3
WBB
1 3
WBW
1 3
WWB
1 3
WWW
2 2
BB
BB
2 2
BB
BW
2 2
BB
WB
2 2
BB
WW
2 2
BW
BB
2 2
BW
BW
2 2
BW
WB
2 2
BW
WW
2 2
WB
BB
2 2
WB
BW
2 2
WB
WB
2 2
WB
WW
2 2
WW
BB
2 2
WW
BW
2 2
WW
WB
2 2
WW
WW
3 1
B
B
B
3 ...

output:

YES
0
YES
1
RD
YES
1
DR
YES
2
RD
DR
YES
2
RD
DR
YES
1
DR
YES
1
RD
YES
0
YES
0
YES
1
RRD
YES
2
RRD
RDR
YES
1
RDR
YES
3
RRD
RDR
DRR
YES
2
RDR
DRR
YES
1
DRR
YES
2
RRD
DRR
YES
2
RRD
DRR
YES
1
DRR
YES
2
RDR
DRR
YES
3
RRD
RDR
DRR
YES
1
RDR
YES
2
RRD
RDR
YES
1
RRD
YES
0
YES
0
YES
2
DRD
DDR
YES
1
RDD
YES
3
...

result:

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