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+ import sys
2+ from itertools import *
3+
4+ input = sys .stdin .readline
5+
6+ n = int (input ())
7+ a = list (map (int , input ().split ()))
8+
9+ operator_cnt = list (map (int , input ().split ()))
10+
11+ max_value = float ('-inf' )
12+ min_value = float ('inf' )
13+
14+
15+ def bf (value , idx ):
16+ global max_value , min_value
17+ if idx == n :
18+ max_value = max (max_value , value )
19+ min_value = min (min_value , value )
20+ return
21+ if operator_cnt [0 ] > 0 :
22+ operator_cnt [0 ] -= 1
23+ bf (value + a [idx ], idx + 1 )
24+ operator_cnt [0 ] += 1 # 놓친 부분
25+
26+ if operator_cnt [1 ] > 0 :
27+ operator_cnt [1 ] -= 1
28+ bf (value - a [idx ], idx + 1 )
29+ operator_cnt [1 ] += 1
30+
31+ if operator_cnt [2 ] > 0 :
32+ operator_cnt [2 ] -= 1
33+ bf (value * a [idx ], idx + 1 )
34+ operator_cnt [2 ] += 1
35+
36+ if operator_cnt [3 ] > 0 :
37+ operator_cnt [3 ] -= 1
38+ bf (int (value / a [idx ]), idx + 1 ) # 놓친 부분
39+ operator_cnt [3 ] += 1
40+
41+ bf (a [0 ], 1 )
42+ print (max_value )
43+ print (min_value )
Original file line number Diff line number Diff line change 1+ import sys
2+ from itertools import *
3+
4+ input = sys .stdin .readline
5+
6+ n , m = map (int , input ().split ())
7+ arr = sorted (list (map (int , input ().split ())))
8+
9+ for perm in permutations (arr , m ):
10+ print (* perm )
Original file line number Diff line number Diff line change 1+ from collections import *
2+
3+ def is_correct (arr ):
4+ stack = []
5+ for a in arr :
6+ if a in '([{' :
7+ stack .append (a )
8+ elif a == ')' :
9+ if not stack or stack [- 1 ] != '(' :
10+ return False
11+ stack .pop ()
12+ elif a == ']' :
13+ if not stack or stack [- 1 ] != '[' :
14+ return False
15+ stack .pop ()
16+ elif a == '}' :
17+ if not stack or stack [- 1 ] != '{' :
18+ return False
19+ stack .pop ()
20+
21+ return not stack
22+
23+ def solution (s ):
24+ answer = 0
25+ queue = deque (s )
26+
27+ for _ in range (len (queue )):
28+ if is_correct (queue ):
29+ answer += 1
30+ queue .rotate (- 1 )
31+ return answer
You can’t perform that action at this time.
0 commit comments