QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399922#5070. Check Pattern is BadtderWA 1ms3692kbC++142.8kb2024-04-26 19:48:212024-04-26 19:48:21

Judging History

你现在查看的是最新测评结果

  • [2024-04-26 19:48:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3692kb
  • [2024-04-26 19:48:21]
  • 提交

answer

// just for test
// just for test
// just for test
// just for test
// just for test

// 10s...mt19937 yyds!!!
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int dx[4]={-1,-1,0,0},dy[4]={-1,0,-1,0}; // 方向数组
char mp(bool b){return b?'W':'B';}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int t; cin>>t;
  while(t--){
    int n,m; cin>>n>>m;
    mt19937 g(time(0));
    uniform_int_distribution<> u(0,1);
    vector<string> a(n);
    for(auto &i:a)cin>>i;
    auto cl=[&](int x,int y){
      for(int i=0;i<4;i++){
        int x0=x+dx[i],y0=y+dy[i];
        if(~min(x0,y0)&&x0+1<n&&y0+1<m){
          vector<pii> p={
            make_pair(x0,y0),
            make_pair(x0+1,y0),
            make_pair(x0,y0+1),
            make_pair(x0+1,y0+1)};
          // 子矩阵中四个元素
          int c=0;
          for(auto [x1,y1]:p)
            if(make_pair(x1,y1)!=make_pair(x,y)&&a[x1][y1]=='?')c++;
            // 判断其他字符是否是 ?
          if(c)continue; // 该子矩阵不能确定
          switch(i){
            case 0:
              if(a[x0+1][y0]==a[x0][y0+1]&&a[x0+1][y0]!=a[x0][y0])
                if(a[x][y]==a[x0][y0])return false;
                else a[x][y]=a[x0+1][y0];
              break;
              // 先判矛盾然后染色
            case 1:
              if(a[x0][y0]==a[x0+1][y0+1]&&a[x0][y0+1]!=a[x0][y0])
                if(a[x][y]==a[x0][y0+1])return false;
                else a[x][y]=a[x0][y0];
              break;
            case 2:
              if(a[x0][y0]==a[x0+1][y0+1]&&a[x0+1][y0]!=a[x0][y0])
                if(a[x][y]==a[x0+1][y0])return false;
                else a[x][y]=a[x0][y0];
              break;
            case 3:
              if(a[x0+1][y0]==a[x0][y0+1]&&a[x0+1][y0]!=a[x0+1][y0+1])
                if(a[x][y]==a[x0+1][y0+1])return false;
                else a[x][y]=a[x0+1][y0];
              break;
          }
        }
      }
      return true;
    }; // 染色构造,返回值为是否有矛盾
    bool f=true;
    for(int i=0;i<n&&f;i++)
      for(int j=0;j<m&&f;j++)f&=cl(i,j);
    for(int i=n-1;~i&&f;i--)
      for(int j=m-1;~j&&f;j--)f&=cl(i,j); // 记得把漏下的做一遍
    	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) cout<<a[i][j];
		cout<<endl;
	}
	cout<<endl;
	if(!f){/* cout<<"NO\n"; */ continue;} // 无解
    while(1){
      vector<string> r=a; f=true;
      for(int i=0;i<n&&f;i++)
        for(int j=0;j<m&&f;j++)
          if(a[i][j]=='?')
            if(f&=cl(i,j);a[i][j]=='?')a[i][j]=mp(u(g));
            // 随机一下
      for(int i=0;i<n&&f;i++)
        for(int j=0;j<m&&f;j++)f&=cl(i,j); // 判断解的合法性
      if(f)break; a=r;
    }
    // cout<<"YES\n";
    // for(auto i:a)cout<<i<<'\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3692kb

input:

3
2 2
??
??
3 3
BW?
W?B
?BW
3 3
BW?
W?W
?W?

output:

??
??

BW?
WWB
?BW

BW?
WWW
?W?


result:

wrong answer Token parameter [name=yesno] equals to "??", doesn't correspond to pattern "YES|NO" (test case 1)