File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
백준/Silver/15663. N과 M (9) Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 11import sys
22input = sys .stdin .readline
3- from itertools import permutations
43
5- N , M = map (int , input ().split ())
4+ n , m = map (int , input ().split ())
65nums = list (map (int , input ().split ()))
76nums .sort ()
7+ res = list ()
8+ visited = [False ] * n
89
9- A = sorted (list (set (permutations (nums , M ))))
10+ def bt (depth ):
11+ if depth == m :
12+ print (* res )
13+ return
14+ prev = 0
15+ for i in range (n ):
16+ if not visited [i ] and prev != nums [i ]:
17+ prev = nums [i ]
18+ visited [i ] = True
19+ res .append (prev )
20+ bt (depth + 1 )
21+ visited [i ] = False
22+ res .pop ()
1023
11- for i in A :
12- print (* i )
24+ bt (0 )
Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 114496 KB, 시간: 136 ms
7+ 메모리: 112872 KB, 시간: 132 ms
88
99### 분류
1010
1111백트래킹
1212
1313### 제출 일자
1414
15- 2025년 4월 7일 14:05:01
15+ 2025년 4월 7일 14:21:12
1616
1717### 문제 설명
1818
You can’t perform that action at this time.
0 commit comments