Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: kf._.exe

Problemset: Othello

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-17 22:37:27

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define dbg(x) cout << #x << " = " << x  << '\n';
#define int long long
#define dd double
#define ld long double

int cntw = 0,cntb = 0;
vector<string> s(8,string(8,'_'));
#define chk(n,m) (n >= 8 || n < 0 || m >= 8 || m < 0)

bool isfull(){
     for(string &x:s){
          for(char &y:x){
               if(y == '_') return false;
          }
     }
     return true;
}

bool _update(int n,int m,int a,int b,char c){
     if(chk(n, m) || s[n][m] == '_') return false;
     if(s[n][m] == c) return true;

     if(_update(n+a, m+b , a, b, c)) {
          s[n][m] = c;
          return true;
     }
     return false;
}


void update(int n,int m,char c){
     _update(n+1, m, 1, 0, c);
     _update(n-1, m, -1, 0, c);
     _update(n, m+1, 0, 1, c);
     _update(n, m-1, 0, -1, c);
     _update(n+1, m+1, 1, 1, c);
     _update(n-1, m-1, -1, -1, c);
     _update(n+1, m-1, 1, -1 ,c);
     _update(n-1, m+1, -1, 1 ,c);

}

void solve(){
     // input 
     for(string &x:s) {
          cin >> x;
          for(char &y:x){
               if(y == 'W') cntw++;
               if(y == 'B') cntb++;
          }
     }
     char c='B';

     //logic
     while(1){
          int n,m;cin >> n >> m;
          if(n==-1&&m==-1) break;
          if(s[n][m] != '_'){
              // c = (c == 'B')? 'W' : 'B';
               continue;
          }
          s[n][m] = c;

          update(n,m,c);

          if(isfull()) break;

          c = (c == 'B')? 'W' : 'B';
     } 

     // count 
     cntw = 0,cntb = 0;
     for(string &x:s){
          for(char &y:x){
               if(y == 'W') ++cntw;
               else if(y == 'B') ++cntb;
          }
          cout << x << endl;
     }
     // ans
     if(cntw > cntb ) cout << "white wins";
     else if(cntw < cntb) cout << "black wins";
     else cout << "draw";
     cout << endl;
}

int32_t main(){
     fastio;
     int T = 1;
     //cin >> T
     while(T--) solve();
     return 0;
}