Submission
Status:
------P-----P-P-----
Subtask/Task Score:
15/100
Score: 15
User: Some1258
Problemset: Othello
Language: cpp
Time: 0.004 second
Submitted On: 2026-07-29 09:59:21
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 8;
bool inside(int row, int col) {
return row >= 0 && row < SIZE &&
col >= 0 && col < SIZE;
}
bool makeMove(vector<string>& board, int row, int col, char player) {
if (!inside(row, col) || board[row][col] != '.') {
return false;
}
char opponent = (player == 'B') ? 'W' : 'B';
const int dr[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dc[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<pair<int, int>> allPiecesToFlip;
for (int direction = 0; direction < 8; direction++) {
int currentRow = row + dr[direction];
int currentCol = col + dc[direction];
vector<pair<int, int>> piecesToFlip;
while (inside(currentRow, currentCol) &&
board[currentRow][currentCol] == opponent) {
piecesToFlip.push_back({currentRow, currentCol});
currentRow += dr[direction];
currentCol += dc[direction];
}
if (!piecesToFlip.empty() &&
inside(currentRow, currentCol) &&
board[currentRow][currentCol] == player) {
allPiecesToFlip.insert(
allPiecesToFlip.end(),
piecesToFlip.begin(),
piecesToFlip.end()
);
}
}
// A move is illegal if it flips no pieces.
if (allPiecesToFlip.empty()) {
return false;
}
board[row][col] = player;
for (const auto& position : allPiecesToFlip) {
board[position.first][position.second] = player;
}
return true;
}
int main() {
vector<string> board(SIZE);
for (int row = 0; row < SIZE; row++) {
cin >> board[row];
}
char player = 'B';
int row, col;
while (cin >> row >> col) {
if (row == -1 && col == -1) {
break;
}
// Add these lines if the input coordinates are 1-based:
// row--;
// col--;
if (makeMove(board, row, col, player)) {
player = (player == 'B') ? 'W' : 'B';
}
}
int blackCount = 0;
int whiteCount = 0;
for (const string& boardRow : board) {
cout << boardRow << '\n';
for (char cell : boardRow) {
if (cell == 'B') {
blackCount++;
} else if (cell == 'W') {
whiteCount++;
}
}
}
if (blackCount > whiteCount) {
cout << "black wins\n";
} else if (whiteCount > blackCount) {
cout << "white wins\n";
} else {
cout << "draw\n";
}
return 0;
}