QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440802#5070. Check Pattern is Badnhuang685TL 0ms3536kbC++202.4kb2024-06-14 03:26:092024-06-14 03:26:09

Judging History

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

  • [2024-06-14 03:26:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3536kb
  • [2024-06-14 03:26:09]
  • 提交

answer

/**
 * @file qoj5070-1.cpp
 * @author n685
 * @brief
 * @date 2024-06-13
 *
 *
 */
#include <bits/stdc++.h>

#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbgR(...) 4242
#define dbgP(...) 420
#define dbgRP(...) 420420
void nline() {}
#endif

auto op(char c) -> char {
  assert(c != '?');
  if (c == 'W') {
    return 'B';
  } else {
    return 'W';
  }
}

struct Node {
  int i, j;
  char c;
};

std::mt19937 rng;
void solve() {
  int n, m;
  std::cin >> n >> m;
  std::vector gr(n, std::string(m, '?'));
  std::queue<Node> q;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      std::cin >> gr[i][j];
    }
  }
  bool g = true;
  auto check = [&](int i, int j) {
    if (i < 0 || i >= n || j < 0 || j >= m || gr[i][j] == '?') {
      return;
    }
    for (int ni : {i - 1, i + 1}) {
      if (ni < 0 || ni >= n) {
        continue;
      }
      for (int nj : {j - 1, j + 1}) {
        if (nj < 0 || nj >= m) {
          continue;
        }
        if (gr[ni][j] != '?' && gr[i][nj] != '?' && gr[i][j] != gr[ni][j] &&
            gr[i][j] != gr[i][nj]) {
          q.emplace(ni, nj, op(gr[i][j]));
        }
      }
    }
  };
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      check(i, j);
    }
  }
  auto upd = [&](int i, int j, char c) {
    gr[i][j] = c;
    check(i, j);
    check(i - 1, j);
    check(i + 1, j);
    check(i, j - 1);
    check(i, j + 1);
  };
  auto rq = [&]() {
    while (!q.empty()) {
      auto [i, j, c] = q.front();
      q.pop();
      if (gr[i][j] != '?' && gr[i][j] != c) {
        g = false;
        return;
      }
      upd(i, j, c);
    }
  };
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      rq();
      if (!g) {
        std::cout << "NO\n";
        return;
      }
      if (gr[i][j] == '?') {
        upd(i, j, (rng() % 2 ? 'B' : 'W'));
      }
    }
  }
  rq();
  if (!g) {
    std::cout << "NO\n";
    return;
  }
  std::cout << "YES\n";
  for (int i = 0; i < n; ++i) {
    std::cout << gr[i] << '\n';
  }
}

auto main() -> int {
#ifndef LOCAL
  std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
  auto seed = std::chrono::steady_clock::now().time_since_epoch().count();
  // auto seed = 3258875359113;
  dbg(seed);
  rng.seed(seed);

  int t;
  std::cin >> t;
  // std::scanf("%d", &t);
  while (t--) {
    solve();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

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

output:

YES
BB
BB
NO
YES
BWW
WWW
BWW

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:


result: