发火鸡了吗?# Joke - 肚皮舞运动
h*i
1 楼
O(n*n)怎么也过不了large test?
void solve(vector> &board) {
int m = board.size();
if (m == 0) return;
int n = board[0].size();
unordered_set checked;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (board[i][j] == 'X') continue;
if (checked.find(i * n + j) != checked.end()) continue;
unordered_set s;
queue q;
s.insert(i * n + j);
q.push(i * n + j);
bool fill = true;
while (!q.empty()) {
int k = q.front();
q.pop();
int jj = k % n;
int ii = k / n;
checked.insert(ii * n + jj);
if (ii == 0 || ii == m - 1 || jj == 0 || jj == n - 1)
fill = false;
if (ii + 1 < m && board[ii+1][jj] == 'O') {
s.insert((ii + 1) * n + jj);
q.push((ii + 1) * n + jj);
}
if (jj + 1 < n && board[ii][jj+1] == 'O') {
s.insert(ii* n + jj + 1);
q.push(ii * n + jj + 1);
}
}
if (fill) {
for (unordered_set::iterator it = s.begin();
it != s.end(); ++it) {
int k = *it;
int jj = k % n;
int ii = k / n;
board[ii][jj] = 'X';
}
}
}
}
}
void solve(vector
int m = board.size();
if (m == 0) return;
int n = board[0].size();
unordered_set
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (board[i][j] == 'X') continue;
if (checked.find(i * n + j) != checked.end()) continue;
unordered_set
queue
s.insert(i * n + j);
q.push(i * n + j);
bool fill = true;
while (!q.empty()) {
int k = q.front();
q.pop();
int jj = k % n;
int ii = k / n;
checked.insert(ii * n + jj);
if (ii == 0 || ii == m - 1 || jj == 0 || jj == n - 1)
fill = false;
if (ii + 1 < m && board[ii+1][jj] == 'O') {
s.insert((ii + 1) * n + jj);
q.push((ii + 1) * n + jj);
}
if (jj + 1 < n && board[ii][jj+1] == 'O') {
s.insert(ii* n + jj + 1);
q.push(ii * n + jj + 1);
}
}
if (fill) {
for (unordered_set
it != s.end(); ++it) {
int k = *it;
int jj = k % n;
int ii = k / n;
board[ii][jj] = 'X';
}
}
}
}
}