Language: C++

'use strict';

const readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin
});
var lineNo = 0;
rl.on('line', (line) => {
    onEachLine(line.trim(), lineNo++);
});
rl.on('close', onInputClosed);
function debug(){
    if( DEBUG ){
        console.log.apply(null, arguments);
    }
}

var DEBUG = 0;

var matrix = [];
var black = [];
var white;
var H;
var W;

function onEachLine(line, lineNo) {
    if( lineNo === 0 ){
        var d = line.split(/\s+/);
        H = parseInt(d[0]);
        W = parseInt(d[0]);
        white = H*W;
        matrix.push(Array(W+2).fill('#'));
        return;
    }
    var row = lineNo;
    line = '#'+line+'#';
    matrix[row] = line.split('');
    for (var i=1,len=matrix[row].length; i<len-1; i++) {
        if (matrix[row][i] === '#') {
            white -= 1;
            black.push([row, i]);
        }
    }
    matrix.push(Array(W+2).fill('#'));
}


function onInputClosed(){
    var neighbour = [[-1, 0],[1,0],[0,-1],[0,1]];
    var nLen = neighbour.length;
    var count = 0;
    black.push([-1,-1]);
    debug(white);
    debug(black);
    debug(matrix);
    while(white>0){
        var b = black.shift();
        if( b[0] === -1 ){
            debug(white);
            debug(black);
            debug(matrix);
            count += 1;
            black.push([-1, -1]);
            continue;
        }
        for(var j=0; j<nLen; j++) {
            var r = b[0] + neighbour[j][0];
            var c = b[1] + neighbour[j][1];
            if(matrix[r][c] === '.' ){
                matrix[r][c] = '#';
                white -= 1;
                if (white <= 0){
                    count += 1;
            debug(white);
            debug(black);
            debug(matrix);
                    break;
                }
                black.push([r,c]);
            }
        }
    }
    console.log(count);
}






Compiler output:
a.cc:1:1: warning: multi-character literal with 10 characters exceeds 'int' size of 4 bytes
    1 | 'use strict';
      | ^~~~~~~~~~~~
a.cc:3:26: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
    3 | const readline = require('readline');
      |                          ^~~~~~~~~~
a.cc:8:7: warning: multi-character character constant [-Wmultichar]
    8 | rl.on('line', (line) => {
      |       ^~~~~~
a.cc:11:7: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   11 | rl.on('close', onInputClosed);
      |       ^~~~~~~
a.cc:28:29: error: stray '\' in program
   28 |         var d = line.split(/\s+/);
      |                             ^
a.cc:37:30: error: empty character constant
   37 |     matrix[row] = line.split('');
      |                              ^~
a.cc:1:1: error: expected unqualified-id before '\x72696374'
    1 | 'use strict';
      | ^~~~~~~~~~~~
a.cc:3:7: error: 'readline' does not name a type
    3 | const readline = require('readline');
      |       ^~~~~~~~
a.cc:4:1: error: 'var' does not name a type
    4 | var rl = readline.createInterface({
      | ^~~
a.cc:6:2: error: expected unqualified-id before ')' token
    6 | });
      |  ^
a.cc:7:1: error: 'var' does not name a type
    7 | var lineNo = 0;
      | ^~~
a.cc:8:1: error: 'rl' does not name a type
    8 | rl.on('line', (line) => {
      | ^~
a.cc:10:2: error: expected unqualified-id before ')' token
   10 | });
      |  ^
a.cc:11:1: error: 'rl' does not name a type
   11 | rl.on('close', onInputClosed);
      | ^~
a.cc:12:1: error: 'function' does not name a type; did you mean 'union'?
   12 | function debug(){
      | ^~~~~~~~
      | union
a.cc:18:1: error: 'var' does not name a type
   18 | var DEBUG = 0;
      | ^~~
a.cc:20:1: error: 'var' does not name a type
   20 | var matrix = [];
      | ^~~
a.cc:21:1: error: 'var' does not name a type
   21 | var black = [];
      | ^~~
a.cc:22:1: error: 'var' does not name a type
   22 | var white;
      | ^~~
a.cc:23:1: error: 'var' does not name a type
   23 | var H;
      | ^~~
a.cc:24:1: error: 'var' does not name a type
   24 | var W;
      | ^~~
a.cc:26:1: error: 'function' does not name a type; did you mean 'union'?
   26 | function onEachLine(line, lineNo) {
      | ^~~~~~~~
      | union
a.cc:48:1: error: 'function' does not name a type; did you mean 'union'?
   48 | function onInputClosed(){
      | ^~~~~~~~
      | union