QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508213 | #5070. Check Pattern is Bad | yyyyxh | WA | 13ms | 3796kb | C++14 | 1.7kb | 2024-08-07 09:42:24 | 2024-08-07 09:42:24 |
Judging History
answer
#include <queue>
#include <cstdio>
using namespace std;
typedef pair<int,int> pii;
const int N=103;
queue<pii> que;
int n,m;
char s[N][N];
bool inq[N][N];
bool check(int x,int y){
if(x<1||x>n) return 0;
if(y<1||y>n) return 0;
if(s[x][y]==s[x+1][y]) return 0;
if(s[x][y]==s[x][y+1]) return 0;
if(s[x+1][y+1]==s[x+1][y]) return 0;
if(s[x+1][y+1]==s[x][y+1]) return 0;
int tx=-1,ty=-1;
if(s[x][y]=='?'){
if(tx<0&&ty<0) tx=x,ty=y;
else return 0;
}
if(s[x+1][y]=='?'){
if(tx<0&&ty<0) tx=x+1,ty=y;
else return 0;
}
if(s[x][y+1]=='?'){
if(tx<0&&ty<0) tx=x,ty=y+1;
else return 0;
}
if(s[x+1][y+1]=='?'){
if(tx<0&&ty<0) tx=x+1,ty=y+1;
else return 0;
}
if(tx<0&&ty<0) return s[x][y]==s[x+1][y+1]&&s[x+1][y]==s[x][y+1];
if(inq[tx][ty]) return 0;
s[tx][ty]=s[2*x+1-tx][2*y+1-ty]^21;
que.emplace(tx,ty);inq[tx][ty]=1;
return 0;
}
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
while(!que.empty()) que.pop();
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j) inq[i][j]=0;
for(int i=1;i<n;++i)
for(int j=1;j<m;++j)
if(check(i,j)){puts("NO");return;}
while(true){
while(!que.empty()){
auto [a,b]=que.front();que.pop();
if(check(a,b)){puts("NO");return;}
if(check(a-1,b)){puts("NO");return;}
if(check(a,b-1)){puts("NO");return;}
if(check(a-1,b-1)){puts("NO");return;}
}
for(int i=1;i<=n&&que.empty();++i)
for(int j=1;j<=m&&que.empty();++j)
if(s[i][j]=='?'){
s[i][j]='B';
inq[i][j]=1;
que.emplace(i,j);
}
if(que.empty()) break;
}
puts("YES");
for(int i=1;i<=n;++i) printf("%s\n",s[i]+1);
putchar('\n');
}
int main(){
int tc;
scanf("%d",&tc);
while(tc--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
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 BB BB NO YES BWB WWW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3796kb
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 BW BB BB WB BB YES BB BB BB BW WW BB NO NO YES B W B B B W W W B B YES BBWW WBWB WWWB BBWW BWWB BWWW WWWB BWWW BBBW BBBW YES WBW WBB BBB BBB WBW WBW BBB BWB YES W B B B YES BBBB WB\x15B YES BBBBBB BBWBWB YES WBWBB YES BWBBBB WWBBBB BBBWBB WBWWBW YES B YES BWB BBB WBB BBB WWB ...
result:
wrong answer Token parameter [name=g[i]] equals to "WB\x15B", doesn't correspond to pattern "[BW]{1,100}" (test case 9)