QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399927 | #5070. Check Pattern is Bad | tder | TL | 0ms | 3712kb | C++14 | 2.5kb | 2024-04-26 19:50:45 | 2024-04-26 19:50:45 |
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: 3712kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BW BW 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 WB BB YES WB WB BB BW WW BB NO YES WWWBWWB BBBWWWB BWBBBBB BBBWBBB YES B W W B B W W W B B NO YES WBW WWW BWW BWW WWW WWW BBB BWB YES W B W B YES WBBB WBBB YES BBBBBB WBWBWB YES WWWWW NO YES B YES BWB BBB WBB WBB WWB WBB BBW WBB NO YES BWWBBW YES BBWB NO YES WBBWW BBBWW BBWB...