[Offer收割]编程练习赛28 register

Ended

Participants:277

Verdict:Time Limit Exceeded
Score:60 / 100
Submitted:2017-09-24 13:38:01

Lang:Python2

Edit
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
s = raw_input()
ans = 0
def get_length_odd(index):
    length = 0
    while index - length >= 0 and index + length < len(s) and \
          s[index - length] == s[index + length]:
        length += 1
    return length
def get_length_even(index):
    length = 0
    while index - length >= 0 and index + 1 + length < len(s) and \
          s[index - length] == s[index + 1 + length]:
        length += 1
    return length
for i in range(len(s)):
    length = get_length_odd(i)
    #print i, length
    ans += length
for i in range(len(s)):
    length = get_length_even(i)
    #print i, length
    ans += length
print ans
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX