이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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... |