QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65353 | #5070. Check Pattern is Bad | Qingyu | WA | 162ms | 3572kb | C++23 | 3.7kb | 2022-11-29 22:08:53 | 2022-11-29 22:08:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 110;
int n, m;
string a[N], ans[N];
unsigned int SA=20060411, SB=20041115, SC=20060512;
unsigned int rng61(){
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
#define rand rng61
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0);
int T, sum = 1e6, cs = 0;
for(cin >> T; T; T --) {
srand(1);
cin >> n >> m;
int area = n * m, st = clock();
for(int i = 1; i <= n; i ++) {
cin >> a[i];
a[i] = "?" + a[i] + "?";
ans[i] = a[i];
}
if(++ cs == 8961) {
cerr << n << ' ' << m << '\n';
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cerr << a[i][j];
}
cerr << '\n';
}
}
ans[0] = ans[n + 1] = string(m + 2, '?');
int flag = 1;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) if(ans[i][j] == '?') {
char c = '?';
for(int dx : {1, -1}) {
for(int dy : {1, -1}) {
if(ans[i][j + dy] == ans[i + dx][j] && ans[i][j + dy] != ans[i + dx][j + dy] && ans[i][j + dy] != '?' && ans[i + dx][j + dy] != '?') {
if(c == '?') c = ans[i][j + dy];
else if(c != ans[i][j + dy]) flag = 0;
}
}
}
ans[i][j] = c;
}
a[i] = ans[i];
}
for(int i = 1; i < n; i ++) {
for(int j = 1; j < m; j ++) {
if(ans[i][j] != ans[i][j + 1] && ans[i][j] != ans[i + 1][j] && ans[i][j] == ans[i + 1][j + 1]) {
if(ans[i][j] != '?' && ans[i][j + 1] != '?' && ans[i + 1][j] != '?') {
flag = 0;
}
}
}
}
if(!flag) {
cout << "NO\n";
continue;
}
// assert(flag);
for(int i = 1; i < 100000; i ++) {
// cout << flag << "1\n";
for(int i = 1; i <= n; i ++) ans[i] = a[i];
for(int i =1; i <= n * m; i ++) {
int ok = 1;
for(int i = 1; i <= n && ok; i ++) {
for(int j = 1; j <= m && ok; j ++) {
if(ans[i][j] == '?') {
ans[i][j] = rand() & 1 ? 'W' : 'B';
ok = 0;
}
}
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) if(ans[i][j] == '?') {
char c = '?';
for(int dx : {1, -1}) {
for(int dy : {1, -1}) {
if(ans[i][j + dy] == ans[i + dx][j] && ans[i][j + dy] != ans[i + dx][j + dy] && ans[i][j + dy] != '?' && ans[i + dx][j + dy] != '?') {
if(c == '?') c = ans[i][j + dy];
else if(c != ans[i][j + dy]) flag = 0;
}
}
}
ans[i][j] = c;
}
}
}
// cout << flag << "2\n";
int flag = 1;
for(int i = 1; i < n; i ++) {
for(int j = 1; j < m; j ++) {
if(ans[i][j] != ans[i][j + 1] && ans[i][j] != ans[i + 1][j] && ans[i][j] == ans[i + 1][j + 1]) {
if(ans[i][j] != '?' && ans[i][j + 1] != '?' && ans[i + 1][j] != '?') {
flag = 0;
}
}
}
}
if(flag) break;
}
// cout << flag << '\n';
// assert(flag);
for(int i = 1; i < n; i ++) {
for(int j = 1; j < m; j ++) {
if(ans[i][j] != ans[i][j + 1] && ans[i][j] != ans[i + 1][j] && ans[i][j] == ans[i + 1][j + 1]) {
if(ans[i][j] != '?' && ans[i][j + 1] != '?' && ans[i + 1][j] != '?') {
// cout << i << ' ' << j << '\n';
flag = 0;
}
}
}
}
// for(int i = 1; i <= n; i ++) {
// for(int j = 1; j <= m; j ++) {
// cout << ans[i][j];
// }
// cout << '\n';
// }
if(!flag) {
cout << "NO\n";
continue;
}
cout << "YES\n";
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cout << ans[i][j];
}
cout << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3572kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WB BB NO YES BWB WWW BWB
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 153ms
memory: 3516kb
input:
10000 9 2 BB BW WW WW ?W ?B B? W? BB 6 2 ?? ?B B? BW WW ?? 10 7 WBBBW?? ???BWWW ???BWWB ??WWBW? BBWBBWB WWB?WW? BWBW??? WWWWBBW BBWBB?W B?W?W?B 4 7 ??WBWWB ?BBWWWB ?W?BBB? BBBWBBB 10 1 B W ? B B W W W B ? 10 4 ??WW W?W? WWW? ???W ?W?? ?W?W W?W? ?W?W ???W ???W 8 3 WBW W?? ??? ??? W?W W?W ??? ?W? 4 1 ...
output:
YES BB BW WW WW WW BB BB WB BB YES BB WB BB BW WW BW NO NO YES B W B B B W W W B W YES BBWW WWWB WWWW WWWW BWBW BWBW WWWW BWBW WWBW BBBW YES WBW WWW WWW BWB WWW WBW BBW BWW YES W B B W YES WBBB WBBB YES BWBBBB WWWWWB YES WBWBW YES BWWWWB WWBBWB BBBWWB WBWWWW YES B YES BWB BBB WBB BBB WWB WBB BBW WBB...
result:
ok ok (10000 test cases)
Test #3:
score: 0
Accepted
time: 115ms
memory: 3544kb
input:
10000 9 6 ?B?W?W WWBBWB ?WB?BW B?W?W? WW??W? B???BW ?W?WW? W?B?B? ?W?BB? 10 1 W ? ? ? ? ? ? ? B W 9 4 ???? ???? W??? ?W?B ??WW ?BW? WW?W ??W? ??W? 3 2 ?W ?B BB 2 7 ?W?BWWB ??W???W 9 9 ?BW?WWW?W BW?WBBWWW W?W????WW W??WW??WW W?BWB?B?W ??BB?WWWW W???WBW?W WWW???WWW B?WWWWWW? 8 10 W??BWWW??B ?BWBWBW?BW...
output:
NO YES W W B B B B B W B W YES BWBW BBBW WBWW WWWB WWWW WBWB WWWW BWWB BBWB YES WW BB BB YES BWBBWWB WWWWWWW NO NO YES WWB BWW BBB WBW WWW YES WWBWWWBBW BBBWWWBBB WWBWWBBBW WWWWWWWBB WWBBBWBBW BWWWWWBWW BWBBBWBWB YES WBWWBWB BBBWWWB BWWWWWW BWWWWWW BBWBWWW WWWBWBB WWWWWWB WWWWWWB BWWWBWW YES WB WB W...
result:
ok ok (10000 test cases)
Test #4:
score: -100
Wrong Answer
time: 162ms
memory: 3452kb
input:
10000 7 7 ?B??BBW ????BB? WBBB??B WW?B??? ?B??BBB BBWB??B B???BB? 10 6 W?WW?? W??W?? ?WWWW? ?WW?WW WW??W? W????? W?WW?? WW???W WWW??W ?W??W? 2 6 ?B??W? B???BB 1 8 ??BWB?W? 5 2 WB W? B? BB ?W 7 5 W???? ?WW?? ???W? WWWW? W?W?W ?W?B? W?WWB 8 5 B?WBW B??WW WWW?B WBBWB BW?WW B?W?B ??WWB BBW?B 10 4 WWWW ?...
output:
YES WBBBBBW BBBBBBW WBBBBBB WWWBBWB BBWBBBB BBWBWWB BWWBBBB YES WWWWBB WWBWBB BWWWWW BWWBWW WWBBWW WWWWWB WWWWBB WWBBBW WWWWBW BWWWWW YES WBBBWB BBWBBB YES BWBWBWWB YES WB WB BB BB WW YES WWWWB BWWWB BBBWB WWWWW WWWBW BWBBB WWWWB NO YES WWWW BBWB WBBB WBWB WWWB BWWW WWBB WBBB WWWW WBWB YES BWWBBB BW...
result:
wrong answer ans finds the answer, but out doesn't (test case 9408)