QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643959 | #5071. Check Pattern is Good | Kevin5307 | WA | 35ms | 3668kb | C++23 | 2.3kb | 2024-10-16 08:57:06 | 2024-10-16 08:57:07 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
string grid[105];
int n,m;
int cnt[105][105];
int vis[105][105];
void check(int x,int y);
void color(int x,int y,char ch)
{
grid[x][y]=ch;
for(int a=0;a<2;a++)
for(int b=0;b<2;b++)
if(x>=a&&y>=b)
{
cnt[x-a][y-b]--;
if(cnt[x-a][y-b]==1)
check(x-a,y-b);
}
}
void check(int x,int y)
{
vis[x][y]=1;
set<char> st;
for(int a=0;a<2;a++)
for(int b=0;b<2;b++)
if(grid[x+a][y+b]!='?')
st.insert(grid[x+a][y+b]);
if(sz(st)==1)
{
for(int a=0;a<2;a++)
for(int b=0;b<2;b++)
if(grid[x+a][y+b]=='?')
color(x+a,y+b,*st.begin());
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>grid[i];
for(int i=0;i<n-1;i++)
for(int j=0;j<m-1;j++)
{
cnt[i][j]=0;
vis[i][j]=0;
for(int x=0;x<2;x++)
for(int y=0;y<2;y++)
if(grid[i+x][j+y]=='?')
cnt[i][j]++;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if((i+j)&1) if(grid[i][j]!='?')
grid[i][j]='B'+'W'-grid[i][j];
for(int i=0;i<n-1;i++)
for(int j=0;j<m-1;j++)
if(cnt[i][j]==1&&!vis[i][j])
check(i,j);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(grid[i][j]=='?')
grid[i][j]='B';
int ans=0;
for(int i=0;i<n-1;i++)
for(int j=0;j<n-1;j++)
{
set<char> st;
for(int a=0;a<2;a++)
for(int b=0;b<2;b++)
st.insert(grid[i+a][j+b]);
if(sz(st)==1)
ans++;
}
cout<<ans<<'\n';
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
if((i+j)&1)
cout<<(char)('B'+'W'-grid[i][j]);
else
cout<<grid[i][j];
cout<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 BW WB 1 BWB WBB BBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 3576kb
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:
51 BB BW WW WW BW WB BW WB BB 17 BW WB BW BW WW WB 27 WBBBWWB WBWBWWW BWBBWWB WBWWBWW BBWBBWB WWBWWWW BWBWBWB WWWWBBW BBWBBWW BBWBWBB 5 BWWBWWB WBBWWWB BWWBBBW BBBWBBB 26 B W B B B W W W B W 25 BWWW WBWB WWWW WBWW BWBW WWWW WWWW WWWW BWBW WBWW 15 WBW WBW BWB WBW WWW WBW BWB WWW 0 W B B W 0 BBBB WBWB...
result:
wrong answer Integer parameter [name=ans] equals to 51, violates the range [0, 18] (test case 1)