QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469707 | #5070. Check Pattern is Bad | BalintR | WA | 28ms | 3944kb | C++20 | 4.1kb | 2024-07-09 22:08:48 | 2024-07-09 22:08:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cpx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound(ALL(v), x) - (v).begin())
#define ubv(v, x) (upper_bound(ALL(v), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cerr << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <typename T, typename U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}
const int MN = 105;
int n, m;
string grid[MN];
int prv[MN][MN], nxt[MN][MN];
bool difA[MN][MN], difB[MN][MN], (*difArr)[MN];
bool resA[MN][MN], resB[MN][MN], (*resArr)[MN];
int stInd[MN][MN];
vector<set<int>> sts;
bool dfs(int x1, int y1){
if(x1 < 0 || x1 >= n || stInd[x1][y1] == -1) return true;
set<int> &st = sts[stInd[x1][y1]];
if(st.find(y1) == st.end()) return true;
st.erase(y1);
if(st.empty()) return false;
if(SZ(st) >= 2) return true;
int y2 = *st.begin();
resArr[x1][y2] = true;
return dfs(x1-1, y2) && dfs(x1+1, y2);
}
bool solveHalf(){
ms(stInd, -1);
FR(i, n){
FR(j, m-1) if(difArr[i][j]){
if(j && stInd[i][j-1] != -1) stInd[i][j] = stInd[i][j-1];
else stInd[i][j] = SZ(sts), sts.pb({});
sts[stInd[i][j]].insert(j);
}
}
FR(i, n) FR(j, m-1) if(stInd[i][j] != -1){
set<int> &st = sts[stInd[i][j]];
if(st.find(j) != st.end() && SZ(st) == 1){
st.clear();
resArr[i][j] = true;
if(!dfs(i-1, j) || !dfs(i+1, j)) return false;
}
}
FR(i, n) FR(j, m-1) if(!dfs(i, j)) return false;
return true;
}
bool solve(){
cin >> n >> m;
FR(i, n) cin >> grid[i];
FR(i, n) if(i & 1) FR(j, m) if(grid[i][j] != '?') grid[i][j] ^= 'W'^'B';
FR(i, n){
char ch = '?';
FR(j, m){
if(grid[i][j] != '?') ch = grid[i][j];
prv[i][j] = ch;
}
ch = '?';
FORR(j, m-1, 0){
if(grid[i][j] != '?') ch = grid[i][j];
nxt[i][j] = ch;
}
FR(j, m){
if(prv[i][j] == '?' && nxt[i][j] == '?') grid[i][j] = 'W';
else if(prv[i][j] == nxt[i][j]) grid[i][j] = prv[i][j];
else if((prv[i][j]^nxt[i][j]) != ('B'^'W')) grid[i][j] = prv[i][j]^nxt[i][j]^'?';
}
FR(j, m-1){
if(prv[i][j] == 'W' && nxt[i][j+1] == 'B') difA[i][j] = true;
if(prv[i][j] == 'B' && nxt[i][j+1] == 'W') difB[i][j] = true;
}
//dbg(grid[i]);
}
difArr = difA;
resArr = resA;
if(!solveHalf()) return false;
sts.clear();
difArr = difB;
resArr = resB;
if(!solveHalf()) return false;
sts.clear();
FR(i, n){
assert(grid[i][0] != '?');
FR(j, m-1) grid[i][j+1] = grid[i][j] ^ (resA[i][j] || resB[i][j])*('W'^'B');
}
FR(i, n) if(i & 1) FR(j, m) grid[i][j] ^= 'W'^'B';
return true;
}
int main(){
cin.sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while(t--){
bool res = solve();
if(res){
cout << "YES\n";
FR(i, n) cout << grid[i] << '\n';
}
else cout << "NO\n";
ms(difA, 0);
ms(difB, 0);
ms(resA, 0);
ms(resB, 0);
}
}
詳細信息
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 WW BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3944kb
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 WW BB YES WW BB BB BW WW BB NO NO YES B W W B B W W W B B YES WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW YES WBW WWW WWW BBB WWW WWW WWW WWW YES W B W B NO YES BBBBBB WWWWWB YES WWWWW YES BWWWWW WWBBBB BBBWWW WWWWWW YES W NO YES BBBBBBB BBBBBBB BBBBBBB BBBBBBB BBBBBBB...
result:
wrong answer ans finds the answer, but out doesn't (test case 9)