Submission

Status:

PP--P-P-----P-P-----

Subtask/Task Score:

30/100

Score: 30

User: matcherbrainner

Problemset: Othello

Language: cpp

Time: 0.005 second

Submitted On: 2026-11-28 21:13:29

#include<bits/stdc++.h>
using namespace std;
char a[8][8];
int dr[8]={-1,-1,-1,0,0,1,1,1};
int dc[8]={-1,0,1,-1,1,-1,0,1};
bool inside(int r,int c){
    return r>=0&&r<8&&c>=0&&c<8;
}
int play(int r,int c,char color){
    if(!inside(r,c)||a[r][c]!='_')
    return 0;
    char opp;
    if(color=='B')opp='W';
    else opp='B';
    int total=0;
    for(int d=0;d<8;d++){
        int x=r+dr[d];
        int y=c+dc[d];
        int cnt=0;
        int rr[8],cc[8];
        while(inside(x,y)&&a[x][y]==opp){
            rr[cnt]=x;
            cc[cnt]=y;
            cnt++;
            x+=dr[d];
            y+=dc[d];
        }
        if(cnt>0&&inside(x,y)&&a[x][y]==color){
            for(int i=0;i<cnt;i++){
                a[rr[i]][cc[i]]=color;
            }
            total+=cnt;
        }
    }    
    if(total>0){
        a[r][c]=color;
    }
    return total;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            cin>>a[i][j];
        }
    }
    char color='B';
    int r,c;
    while(cin>>r>>c){
        if(r==-1&&c==-1)break;
        if(play(r,c,color)>0){
            if(color='B')color='W';
            else color='B';
        }
            int full=1;
            for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){
                    if(a[i][j]=='_')full=0;
                }
            }
            if(full)break;
        }
        int b=0,w=0;
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                cout<<a[i][j];
                if(a[i][j]=='B')b++;
                if(a[i][j]=='W')w++;
            }
            cout<<"\n";
        }
        if(b>w)cout<<"black wins";
        else if(w>b)cout<<"white wins";
        else cout<<"draw";
        
}