Submission #1450763


Source Code Expand

X = input()
# X = 'SSTTST'
# X = 'TSSTTTSS'

# naive case
# len_prev = -1
# while len_prev != len(X):
#     len_prev = len(X)
#     X = X.replace('ST', '')
# print(len(X))


i = 0
cnt = []
X += " "
cur = 1
for i in range(len(X) - 1):
    if X[i] == X[i + 1]:
        cur += 1
    else:
        cnt.append((X[i], cur))
        cur = 1

total = 0
for i in range(len(cnt) - 1):
    if cnt[i][0] == 'S':
        if cnt[i][1] > cnt[i + 1][1]:
            if i + 2 < len(cnt):
                cnt[i + 2] = (cnt[i + 2][0], cnt[i + 2][1] + cnt[i][1] - cnt[i + 1][1])
        total += min(cnt[i][1], cnt[i + 1][1])
print(len(X) - 1 - 2 * total)

Submission Info

Submission Time
Task A - STring
User lol
Language Python (3.4.3)
Score 300
Code Size 669 Byte
Status AC
Exec Time 157 ms
Memory 10976 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 3
AC × 9
AC × 13
Set Name Test Cases
Sample example0, example1, example2
Subtask1 example0, example1, example2, sub_corner0, sub_corner1, sub_corner2, sub_rand0, handmade0, handmade1
All corner0, corner1, corner2, example0, example1, example2, handmade0, handmade1, maxrand0, sub_corner0, sub_corner1, sub_corner2, sub_rand0
Case Name Status Exec Time Memory
corner0 AC 65 ms 3496 KB
corner1 AC 63 ms 3500 KB
corner2 AC 95 ms 5732 KB
example0 AC 17 ms 3064 KB
example1 AC 17 ms 3064 KB
example2 AC 17 ms 3064 KB
handmade0 AC 17 ms 3064 KB
handmade1 AC 17 ms 3064 KB
maxrand0 AC 157 ms 10976 KB
sub_corner0 AC 17 ms 3064 KB
sub_corner1 AC 17 ms 3064 KB
sub_corner2 AC 17 ms 3064 KB
sub_rand0 AC 17 ms 3064 KB