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+ min_value = float ('inf' )
2+ max_value = float ('-inf' )
3+
4+ def main ():
5+ N = int (input ())
6+ A = list (map (int , input ().split ()))[:N ]
7+ operator = list (map (int , input ().split ()))[:4 ]
8+
9+ def dfs (i , now ):
10+ global min_value , max_value
11+
12+ if i == N :
13+ min_value = min (min_value , now )
14+ max_value = max (max_value , now )
15+ else :
16+ if operator [0 ] > 0 :
17+ operator [0 ] -= 1
18+ dfs (i + 1 , now + A [i ])
19+ operator [0 ] += 1
20+ if operator [1 ] > 0 :
21+ operator [1 ] -= 1
22+ dfs (i + 1 , now - A [i ])
23+ operator [1 ] += 1
24+ if operator [2 ] > 0 :
25+ operator [2 ] -= 1
26+ dfs (i + 1 , now * A [i ])
27+ operator [2 ] += 1
28+ if operator [3 ] > 0 :
29+ operator [3 ] -= 1
30+ if now < 0 :
31+ dfs (i + 1 , - (- now // A [i ]))
32+ else :
33+ dfs (i + 1 , now // A [i ])
34+ operator [3 ] += 1
35+
36+ dfs (1 , A [0 ])
37+
38+ print (max_value )
39+ print (min_value )
40+
41+ if __name__ == "__main__" :
42+ main ()
Original file line number Diff line number Diff line change 1+ import itertools
2+
3+ def main ():
4+ N , M = map (int , input ().split ())
5+ A = list (map (int , input ().split ()))[:N ]
6+
7+ A .sort ()
8+
9+ for i in itertools .permutations (A , M ):
10+ print (* i )
11+
12+ if __name__ == "__main__" :
13+ main ()
Original file line number Diff line number Diff line change 1+ def solution (s ):
2+ count = 0
3+
4+ rightGaulHoList = ["()" , "[]" , "{}" ]
5+
6+ for i in range (len (s )):
7+ stack = []
8+ rotated = s [i :] + s [:i ]
9+
10+ isPerfect = False
11+
12+ for j in rotated :
13+ if j == "(" or j == "[" or j == "{" :
14+ stack .append (j )
15+
16+ elif j == ")" or j == "]" or j == "}" :
17+ if stack :
18+ total = stack [- 1 ] + j
19+
20+ if total in rightGaulHoList :
21+ stack .pop ()
22+ isPerfect = True
23+ else :
24+ isPerfect = False
25+ break
26+
27+ else :
28+ isPerfect = False
29+ break
30+
31+ if isPerfect and not stack :
32+ count += 1
33+
34+ return count
You can’t perform that action at this time.
0 commit comments