-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_10.py
165 lines (153 loc) · 1.03 KB
/
12_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from utils import *
inp = """
26
97
31
7
2
10
46
38
112
54
30
93
18
111
29
75
139
23
132
85
78
99
8
113
87
57
133
41
104
98
58
90
13
91
20
68
103
127
105
114
138
126
67
32
145
115
16
141
1
73
45
119
51
40
35
150
118
53
80
79
65
135
74
47
128
64
17
4
84
83
147
142
146
9
125
94
140
131
134
92
66
122
19
86
50
52
108
100
71
61
44
39
3
72"""
inp2 = """28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3"""
nums = [int(i) for i in inp.split()]
builtin = max(nums) + 3
nums = sorted(nums) + [builtin]
c = 0
ones = 0
threes = 0
for n in nums:
if n - c == 1:
ones += 1
elif n - c == 3:
threes += 1
c = n
print(ones * threes)
cache = {}
def arrangements(adapters):
tgt = adapters[-1]
if tgt in cache:
return cache[tgt]
if tgt == 0:
return 1
srcs = [a for a in adapters[-4:] if 1 <= tgt - a <= 3]
ans = sum([arrangements([a for a in adapters if a <= s]) for s in srcs])
cache[tgt] = ans
return ans
arrs = arrangements([0] + nums)
print(arrs)