This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def kinds(a, b, c):
if a > b: a, b = b, a
if b > c: b, c = c, b
if a > b: a, b = b, a
ans = 3
if not a or a == b: ans -= 1
if not b or b == c: ans -= 1
return ans
INF = 0x3fffffff
input()
s = [1 if i == 'B' else 2 if i == 'F' else 3 for i in input()]
dp1 = [-INF] * 2 ** 8
dp1[0] = 0
for c in s:
dp2 = [-INF] * 2 ** 8
for i in range(2 ** 8):
a1 = i >> 6 & 3
a2 = i >> 4 & 3
b1 = i >> 2 & 3
b2 = i & 3
j = a2 << 6 | c << 4 | b1 << 2 | b2
dp2[j] = max(dp2[j], dp1[i] + kinds(a1, a2, c))
j = a1 << 6 | a2 << 4 | b2 << 2 | c
dp2[j] = max(dp2[j], dp1[i] + kinds(b1, b2, c))
dp1 = dp2
print(max(dp1))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |