File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
Expand file tree Collapse file tree 2 files changed +65
-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+ . map ( Number ) ;
7+
8+ function combination ( n , r ) {
9+ if ( r > n || r < 0 ) return 0 ;
10+ r = Math . min ( r , n - r ) ;
11+ let result = 1 ;
12+ for ( let i = 0 ; i < r ; i ++ ) {
13+ result *= n - i ;
14+ result /= i + 1 ;
15+ }
16+ return result ;
17+ }
18+
19+ function solution ( input ) {
20+ const [ n , m ] = input ;
21+
22+ if ( n > m ) return 0 ;
23+
24+ const remainingFruits = m - n ;
25+ const result = combination ( remainingFruits + n - 1 , n - 1 ) ;
26+ return result ;
27+ }
28+
29+ console . log ( solution ( input ) ) ;
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+ function solution ( input ) {
8+ let index = 0 ;
9+ const T = Number ( input [ index ++ ] ) ;
10+ const results = [ ] ;
11+
12+ for ( let t = 0 ; t < T ; t ++ ) {
13+ const n = Number ( input [ index ++ ] ) ;
14+ const clothesMap = { } ;
15+
16+ for ( let i = 0 ; i < n ; i ++ ) {
17+ const [ item , type ] = input [ index ++ ] . split ( ' ' ) ;
18+ if ( clothesMap [ type ] ) {
19+ clothesMap [ type ] ++ ;
20+ } else {
21+ clothesMap [ type ] = 1 ;
22+ }
23+ }
24+
25+ let result = 1 ;
26+ for ( const type in clothesMap ) {
27+ result *= clothesMap [ type ] + 1 ;
28+ }
29+
30+ results . push ( result - 1 ) ;
31+ }
32+
33+ return results . join ( '\n' ) ;
34+ }
35+
36+ console . log ( solution ( input ) ) ;
You can’t perform that action at this time.
0 commit comments