Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: mister_o_hater_no1

Problemset: Othello

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-17 01:27:33

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

vector<string> othello;
void print(){
    for (int i= 0; i< 8; ++i) {
        cout<< othello[i]<< '\n';
    }
}

void right(int y, int x, char c) {
    for (int i= x+ 1; i< 8; ++i) {
        if (othello[y][i]== '_') break;
        else if (othello[y][i]== c) {
            for (int j= i- 1; j> x; --j) {
                othello[y][j]= c;
            }
            break;
        }
    }
}

void left(int y, int x, char c) {
    for (int i= x- 1; i>= 0; --i) {
        if (othello[y][i]== '_') break;
        else if (othello[y][i]== c) {
            for (int j= i+ 1; j< x; ++j) {
                othello[y][j]= c;
            }
            break;
        }
    }
}

void down(int y, int x, char c) {
    for (int i= y+ 1; i< 8; ++i) {
        if (othello[i][x]== '_') break;
        else if (othello[i][x]== c) {
            for (int j= i- 1; j> y; --j) {
                othello[j][x]= c;
            }
            break;
        }
    }
}

void up(int y, int x, char c) {
    for (int i= y- 1; i>= 0; --i) {
        if (othello[i][x]== '_') break;
        else if (othello[i][x]== c) {
            for (int j= i+ 1; j< y; ++j) {
                othello[j][x]= c;
            }
            break;
        }
    }
}

void up_right(int y, int x, char c) {
    int i= y- 1;
    int j= x+ 1;
    while (i>= 0 && j< 8) {
        if (othello[i][j]== '_') break;
        else if (othello[i][j]== c) {
            for (int k= i+ 1, o= j- 1; k< y && o> x; ++k, --o) {
                othello[k][o]= c;
            }
            break;
        }
        --i; ++j;
    }
}

void up_left(int y, int x, char c) {
    int i= y- 1;
    int j= x- 1;
    while (i>= 0 && j>= 0) {
        if (othello[i][j]== '_') break;
        else if (othello[i][j]== c) {
            for (int k= i+ 1, o= j+ 1; k< y && o< x; ++k, ++o) {
                othello[k][o]= c;
            }
            break;
        }
        --i; --j;
    }
}

void down_right(int y, int x, char c) {
    int i= y+ 1;
    int j= x+ 1;
    while (i< 8 && j< 8) {
        if (othello[i][j]== '_') break;
        else if (othello[i][j]== c) {
            for (int k= i- 1, o= j- 1; k> y && o> x; --k, --o) {
                othello[k][o]= c;
            }
            break;
        }
        ++i; ++j;
    }
}

void down_left(int y, int x, char c) {
    int i= y+ 1;
    int j= x- 1;
    while (i< 8 && j>= 0) {
        if (othello[i][j]== '_') break;
        else if (othello[i][j]== c) {
            for (int k= i- 1, o= j+ 1; k> y && o< x; --k, ++o) {
                othello[k][o]= c;
            }
            break; 
        }
        ++i; --j;
    }
}

void place(int y, int x, char c) {
    othello[y][x]= c;
}

void winner() {
    int black= 0, white= 0;
    for (int i= 0; i< 8; ++i) {
        for (int j= 0; j< 8; ++j) {
            if (othello[i][j]== 'B') black++;
            else if (othello[i][j]== 'W') white++;
        }
    }
    if (black> white) cout<< "black wins";
    else if (white> black) cout<< "white wins";
    else cout<< "draw";
}

bool full() {
    bool full_check= true;
    for (auto &row: othello) {
        if (row.find('_') != string::npos) full_check = false;
    }
    return full_check;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    string temp; int turn= 0;
    for (int i= 0; i< 8; ++i) {
        cin>> temp;
        othello.push_back(temp);
    }
    int y, x;
    while (cin>> y>> x) {
        if (y== -1 && x== -1) break;
        char c= (turn % 2 == 0 ? 'B' : 'W');
        place(y, x, c);
        right(y, x, c);
        left(y, x, c);
        up(y, x, c);
        down(y, x, c);
        up_right(y, x, c);
        up_left(y, x, c);
        down_right(y, x, c);
        down_left(y, x, c);
        if (full()) break;
        turn++;
    }
    print();
    winner(); 

    return 0;
}