File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ def main ():
2+ n = int (input ())
3+
4+ array = list (map (int , input ().strip ().split ()))[:n ]
5+
6+ x = int (input ())
7+
8+ array .sort ()
9+
10+ count = 0
11+ left , right = 0 , n - 1
12+
13+ while left < right :
14+ sum = array [left ] + array [right ]
15+
16+ if sum == x :
17+ count += 1
18+ left += 1
19+ right -= 1
20+ elif sum < x :
21+ left += 1
22+ else :
23+ right -= 1
24+
25+
26+ print (count )
27+
28+
29+ if __name__ == '__main__' :
30+ main ()
Original file line number Diff line number Diff line change 1+ from itertools import *
2+
3+
4+ def main ():
5+
6+ # 백트래킹을 이용한 방법
7+ N , M = map (int , input ().split ())
8+
9+ def backtrack (start , sequence ):
10+ if len (sequence ) == M :
11+ print (' ' .join (map (str , sequence )))
12+ return
13+
14+ for i in range (start , N + 1 ):
15+ backtrack (i + 1 , sequence + [i ])
16+
17+ backtrack (1 , [])
18+
19+ # combinations를 이용한 방법
20+ N , M = map (int , input ().split ())
21+
22+ for c in combinations (range (1 , N + 1 ), M ):
23+ print (' ' .join (map (str , c )))
24+
25+
26+ if __name__ == '__main__' :
27+ main ()
Original file line number Diff line number Diff line change 1+ def solution (n , computers ):
2+ visited = [False ] * n
3+
4+ def dfs (v ):
5+ visited [v ] = True
6+ for i in range (n ):
7+ if computers [v ][i ] == 1 and not visited [i ]:
8+ dfs (i )
9+
10+ count = 0
11+
12+ for i in range (n ):
13+ if not visited [i ]:
14+ dfs (i )
15+ count += 1
16+
17+ return count
You can’t perform that action at this time.
0 commit comments