File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const fs = require ( "fs" ) ;
22const input = fs
3- . readFileSync ( "./input.txt" , "utf8" )
4- // .readFileSync("/dev/stdin", "utf8")
3+ // .readFileSync("./input.txt", "utf8")
4+ . readFileSync ( "/dev/stdin" , "utf8" )
55 . toString ( )
66 . trim ( )
77 . split ( "\n" )
@@ -10,29 +10,29 @@ const input = fs
1010function solution ( input ) {
1111 const [ N , M ] = input [ 0 ] ;
1212 const arr = input [ 1 ] ;
13- arr . sort ( ( a , b ) => a - b ) ; // 사전 순 출력을 위해 정렬
13+ arr . sort ( ( a , b ) => a - b ) ;
1414
15- const visited = Array ( N ) . fill ( false ) ;
16- const path = [ ] ;
15+ const used = Array ( N ) . fill ( false ) ;
16+ const result = [ ] ;
1717
1818 function dfs ( depth ) {
1919 if ( depth === M ) {
20- console . log ( path . join ( " " ) ) ; // 바로 출력!
20+ console . log ( result . join ( " " ) ) ;
2121 return ;
2222 }
2323
2424 for ( let i = 0 ; i < N ; i ++ ) {
25- if ( visited [ i ] ) continue ;
25+ if ( used [ i ] ) continue ;
2626
27- visited [ i ] = true ;
28- path . push ( arr [ i ] ) ;
27+ used [ i ] = true ;
28+ result . push ( arr [ i ] ) ;
2929 dfs ( depth + 1 ) ;
30- path . pop ( ) ;
31- visited [ i ] = false ;
30+ result . pop ( ) ;
31+ used [ i ] = false ;
3232 }
3333 }
3434
35- dfs ( 0 ) ; // 시작
35+ dfs ( 0 ) ;
3636}
3737
3838solution ( input ) ;
You can’t perform that action at this time.
0 commit comments