32 lines
692 B
Python
32 lines
692 B
Python
|
import sys
|
||
|
|
||
|
def valid(pattern, nums):
|
||
|
l = []
|
||
|
c = ''
|
||
|
for p in pattern:
|
||
|
if p == '#':
|
||
|
c+=p
|
||
|
else:
|
||
|
if len(c):
|
||
|
l.append(c)
|
||
|
c = ''
|
||
|
if len(c):
|
||
|
l.append(c)
|
||
|
c = ''
|
||
|
l = [len(m) for m in l]
|
||
|
return 1 if l == nums else 0
|
||
|
|
||
|
def next(pattern, nums):
|
||
|
i = pattern.find('?')
|
||
|
if i < 0:
|
||
|
return valid(pattern, nums)
|
||
|
else:
|
||
|
return next(pattern[:i]+'.'+pattern[i+1:], nums)+next(pattern[:i]+'#'+pattern[i+1:], nums)
|
||
|
|
||
|
S= 0
|
||
|
for l in sys.stdin.read().splitlines():
|
||
|
pattern, snums = l.split(' ')
|
||
|
nums = list(map(int,snums.split(',')))
|
||
|
S += next(pattern, nums)
|
||
|
print(S)
|