Files
usaco/solving/astral-superposition/main.cpp
T
2026-08-03 19:03:58 +01:00

43 lines
798 B
C++

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int M;
cin >> M;
for (int u = 0; u < M; u++) {
int n, a, b;
cin >> n >> a >> b;
vector<vector<char>> grid(n, vector<char>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
}
}
int res = 0;
for (int i = b; i < n; i++) {
for (int j = a; j < n; j++) {
char c = grid[i][j], pc = grid[i + b][j + a];
if (c == 'B') {
if (pc == 'W') {
res = -1;
goto fin;
} else {
res += 2;
}
} else if (c == 'W') {
continue;
} else {
res++;
}
}
}
fin:
cout << res;
}
}