QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399918 | #5070. Check Pattern is Bad | tder | TL | 0ms | 3708kb | C++14 | 2.5kb | 2024-04-26 19:43:38 | 2024-04-26 19:43:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e2 + 5;
int t, n, m; char a[N][N], r[N][N];
const int dx[4] = {-1, -1, 0, 0};
const int dy[4] = {-1, 0, -1, 0};
bool same(int x1, int y1, int x2, int y2) {
return (a[x1][y1] == a[x2][y2]);
}
bool equal(int x1, int y1, int x2, int y2) {
return (same(x1, y1, x2, y2) || a[x1][y1] == '?' || a[x2][y2] == '?');
}
bool work(int x1, int y1, int x2, int y2) {
return equal(x1, y1, x2, y2) && equal(x1, y2, x2, y1) && (!same(x1, y1, x1, y2) || !same(x1, y1, x2, y1) || !same(x2, y1, x2, y2) || !same(x1, y2, x2, y2));
}
char near(int x, int y, int x1, int y1, int x2, int y2) {
int xx = x, yy = (y == y1 ? y2 : y1);
return a[xx][yy];
}
int check(int x, int y) {
if(a[x][y] != '?') return 1;
for(int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if(nx < 1 || nx + 1 > n || ny < 1 || ny + 1 > m) continue;
// cout<<"in "<<nx<<" "<<ny<<endl;
int b = 1;
for(int xx = 0; xx < 2 && b; xx++) for(int yy = 0; yy < 2 && b; yy++) {
int tx = nx + xx, ty = ny + yy;
if(x != tx && y != ty && a[tx][ty] == '?') b = 0;
}
if(!b) continue;
if(work(nx, ny, nx + 1, ny + 1))
if(a[x][y] != '?' && a[x][y] != near(x, y, nx, ny, nx + 1, ny + 1)) {
// cout<<"check "<<x<<" "<<y<<" = "<<0<<endl;
return 0;
} else {
a[x][y] = near(x, y, nx, ny, nx + 1, ny + 1);
// cout<<"a["<<x<<"]["<<y<<"] = "<<a[x][y]<<endl;
}
}
// cout<<"check "<<x<<" "<<y<<" = "<<1<<endl;
return 1;
}
void solve() {
cin>>n>>m;
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin>>a[i][j];
int b = 1;
for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) b = min(b, check(i, j));
for(int i = n; i >= 1 && b; i--) for(int j = m; j >= 1 && b; j--) b = min(b, check(i, j));
if(!b) {
cout<<"NO"<<endl;
return;
}
cout<<"YES"<<endl;
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j++) cout<<a[i][j];
// cout<<endl;
// }
while(1) {
memcpy(r, a, sizeof(r));
b = 1;
for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) {
b = min(b, check(i, j));
if(a[i][j] == '?') a[i][j] = ((rand() % 2) ? 'B' : 'W');
}
for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) b = min(b, check(i, j));
if(b) break;
memcpy(a, r, sizeof(a));
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) cout<<a[i][j];
cout<<endl;
}
}
signed main() {
srand(time(0));
cin>>t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WB BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
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 WW BB YES BB BB BB BW WW WW NO YES BBWBWWB BBBWWWB BWBBBBB BBBWBBB YES B W B B B W W W B W NO YES WBW WWW BBW BBB WWW WWW BBB BWB YES W B B B YES WBBB WBBB YES BBBBBB BBWWWB YES WWWWB NO YES B YES BWB BBB WBB BBB WWB WBB BBW WBW NO YES BWWBBW YES BBWB NO YES WWWWW BBBWW BBWB...