Submission
Status:
PPPPPP-PPPPP-P----PP
Subtask/Task Score:
70/100
Score: 70
User: YoruoniVamp
Problemset: Othello
Language: cpp
Time: 0.007 second
Submitted On: 2025-09-28 14:49:10
// YoruoniVamp - VTUBE
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
const int dy[] = {-1,-1,0,1,1,1,0,-1}, dx[] = {0,1,1,1,0,-1,-1,-1};
string board[10];
int r, c, cnt, b, w;
bool isblack = true, backtrack = false;
void chk(int i, int j, int direc, char tolorm, bool notfirst) {
// cout << i << ' ' << j << ' ' << direc << ' ' << tolorm << endl;
if(i<1||i>8||j<1||j>8) return;
if(board[i][j]=='_') return;
if(notfirst&&board[i][j]==tolorm) {
// cout << "start to backtrack" << endl;
backtrack = true;
return;
}else {
// cout << "not backtracking" << endl;
if(direc!=-1) {
// cout << "go direc: " << direc << endl;
chk(i+dy[direc],j+dx[direc],direc,tolorm,notfirst);
}else {
for(int d = 0; d < 8; ++d) {
// cout << "i,j: " << i << ' ' << j << endl;
// cout << "dy,dx: " << dy[d] << ' ' << dx[d] << endl;
// cout << "go: " << i+dy[d] << ' ' << j+dx[d] << endl;
chk(i+dy[d],j+dx[d],d,tolorm,true);
backtrack = false;
}
}
}
if(backtrack) {
// cout << w << ' ' << b << endl;
board[i][j] = tolorm;
if(tolorm=='B') --w, ++b;
else --b, ++w;
}
return;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);cout.tie(0);
for(int i = 1; i <= 8; ++i) {
cin >> board[i];
for(char c: board[i]) {
if(c=='B') {
++cnt;
++b;
}else if(c=='W') {
++cnt;
++w;
}
}
board[i].insert(board[i].begin(),' ');
}
// cout << w << ' ' << b << endl;
// cout << "---" << endl;
while(true) {
if(cnt==64) break;
cin >> r >> c;
if(r==-1&&c==-1) break;
++r, ++c;
if(isblack) board[r][c] = 'B', ++b;
else board[r][c] = 'W', ++w;
isblack = !isblack;
// cout << "bef: " << w << ' ' << b << endl;
chk(r,c,-1,board[r][c],false);
// cout << "after: " << w << ' ' << b << endl;
// cout << endl;
}
for(int i = 1; i <= 8; ++i) {
for(int j = 1; j <= 8; ++j) cout << board[i][j];
cout << endl;
}
cout << (b==w?"draw":(b>w?"black wins":"white wins"));
// cout << endl;
// cout << cnt <<' ' << w << ' ' << b << endl;
return 0;
}