Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: pxsit

Problemset: Othello

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-06 18:05:39

#include <bits/stdc++.h>
using namespace std;

int main(){
	char grid[8][8];
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			cin >> grid[i][j];
		}
	}
	int dx[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
	int dy[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
	bool black_color = true;
	while(true){
		int r,c;
		cin >> r >> c;
		if(r == -1 && c == -1) break;
		char cur, opp;
		if(black_color){ cur = 'B'; opp = 'W'; }
		else { cur = 'W'; opp = 'B'; }
		grid[r][c] = cur;
		for(int d=0;d<8;d++){
			int x = r + dx[d];
			int y = c + dy[d];
			int cnt = 0;
			while(x >= 0 && x < 8 && y >= 0 && y < 8 && grid[x][y] == opp){
				x += dx[d];
				y += dy[d];
				cnt++;
			}
			if(cnt > 0 && x >= 0 && x < 8 && y >= 0 && y < 8 && grid[x][y] == cur){
				int fx = r + dx[d];
				int fy = c + dy[d];
				for(int k=0;k<cnt;k++){
					grid[fx][fy] = cur;
					fx += dx[d];
					fy += dy[d];
				}
			}
		}
		int black = 0,white = 0;
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++){
				if(grid[i][j] == 'W') white++;
				else if(grid[i][j] == 'B') black++;
			}
		}
		if(black+white == 64) break;
		if(black_color) black_color = false;
		else black_color = true;
	}
	int black = 0,white = 0;
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			cout << grid[i][j];
			if(grid[i][j] == 'W') white++;
			else if(grid[i][j] == 'B') black++;
		}
		cout << '\n';
	}
	if(black == white) cout << "draw";
	else if(black > white) cout << "black wins";
	else cout << "white wins";
}