-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaekJoon2011.py
More file actions
36 lines (28 loc) · 807 Bytes
/
BaekJoon2011.py
File metadata and controls
36 lines (28 loc) · 807 Bytes
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
# BaekJoon2011.py
import sys
sys.setrecursionlimit(10000)
def solution(s):
global mem
length = len(s)
if length == 0 or (length == 1 and int(s) != 0):
return 1
elif length in mem:
return mem[length]
else:
if 10 <= int(s[-2:]) <= 26 and int(s[-1]) != 0:
tmp = solution(s[:-1]) + solution(s[:-2])
elif (10 > int(s[-2:]) or int(s[-2:]) > 26) and int(s[-1]) != 0:
tmp = solution(s[:-1])
elif 10 <= int(s[-2:]) <= 26 and int(s[-1]) == 0:
tmp = solution(s[:-2])
else:
tmp = 0
if length not in mem:
mem[length] = tmp % 1000000
return tmp % 1000000
secret = input()
mem = {}
if len(secret) == 0 or int(secret) == 0:
print(0)
else:
print(solution(secret))