Submission

Status:

PPP-PPPP-P--PPP-P-PP

Subtask/Task Score:

70/100

Score: 70

User: august

Problemset: Othello

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-02 23:17:11

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

bool edge(int i, int j) {
    return (i>=0 && i<8 && j>=0 && j<8);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    char b[8][8];

    for (int i=0; i<8; i++) {
        string s;
        cin>> s;
        for (int j=0; j<8; j++) {
            b[i][j]=s[j];
        }
    }

    int di[] = {-1,-1,-1,0,1,1,1,0}, dj[] = {-1,0,1,1,1,0,-1,-1};
    int t=0;
    while (true) {
        int r,c;
        cin>> r>> c;
        if ((r==-1 && c==-1) || b[r][c] != '_') break;
        if (t%2==0) b[r][c] = 'B';
        else b[r][c] = 'W';
        
        for (int e=0; e<8; e++) {
            int ni=di[e]+r, nj=dj[e]+c;
            
            if (!edge(ni,nj)) continue;
            if (t%2==0) {
                if (b[ni][nj] == 'W' && edge(ni+di[e],nj+dj[e]) && b[ni+di[e]][nj+dj[e]]=='B') {
                    b[ni][nj] = 'B';
                }
            }
            else {
                if (b[ni][nj] == 'B' && edge(ni+di[e],nj+dj[e]) && b[ni+di[e]][nj+dj[e]]=='W') {
                    b[ni][nj] = 'W';
                }
            }
        }
        t++;
    }
    int black=0, whi=0;
    for (int i=0; i<8; i++) {
        for (int j=0; j<8; j++) {
            cout<< b[i][j];
            if (b[i][j] == 'B') black++;
            else if (b[i][j] == 'W') whi++;
        }
        cout<< "\n";
    }
    if (black > whi) cout<< "black wins";
    else if (black == whi) cout<< "draw";
    else cout<< "white wins";
}