File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( )
5+ . split ( '\n' ) ;
6+
7+ const [ N , M , K ] = input [ 0 ] . split ( ' ' ) . map ( Number ) ;
8+ const board = input . slice ( 1 ) . map ( ( el ) => el [ 0 ] . split ( '' ) ) ;
9+
10+ const sumB = Array . from ( { length : N } , ( ) => Array ( M ) . fill ( 0 ) ) ;
11+ const sumW = Array . from ( { length : N } , ( ) => Array ( M ) . fill ( 0 ) ) ;
12+ console . log ( sumB ) ;
13+
14+ function calculateSum ( board , sum , start ) {
15+ for ( let i = 0 ; i < board . length ; i ++ ) {
16+ for ( let j = 0 ; j < board [ i ] . length ; j ++ ) {
17+ let count = 0 ;
18+ if ( ( i + j ) % 2 === 0 ) {
19+ count = board [ i ] [ j ] === start ? 1 : 0 ;
20+ } else {
21+ count = board [ i ] [ j ] === start ? 0 : 1 ;
22+ }
23+ sum [ i ] [ j ] = sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] + count ;
24+ }
25+ }
26+ }
27+
28+ calculateSum ( board , sumB , 'B' ) ;
29+ calculateSum ( board , sumW , 'W' ) ;
You can’t perform that action at this time.
0 commit comments