Submission #68928649


Source Code Expand

import sys
sys.setrecursionlimit(10 ** 6)

# import numpy as np
# <nonumba> from numba import njit, jit, boolean, int64, float64, typeof




def main():
    from io import StringIO
    execute(StringIO(sample), sys.stderr)
    print("-- ^sample! --", file=sys.stderr)

    execute(sys.stdin, sys.stdout)

    # #<nonumba> if len(solve.nopython_signatures) != 1:
    # #<nonumba>     raise KeyboardInterrupt("!! Unexpected: wrong use of jit !!")

def execute(src, dst):

    N = int(src.readline())
    S = src.readline().strip()

    ans = solve(N, S)
    print(ans, file=dst)

sample = """\
3
AABBBA
"""

# #<nonumba> @jit(nopython=True, cache=True)
def solve(N, S):
    sl = list(S)
    AB = ["A"] + sl + ["x"]
    BA = ["B"] + sl + ["x"]
    ans = min(count(AB) , count(BA))
    return ans

def count(a):
    cost = 0
    nexts = {"A": 0 , "B": 0}
    for i in range(len(a)-1):
        nowc = a[i]
        j = max (i, nexts[nowc])
        while a[i] == a[j]:
            j += 1
        costinc = j - (i+1)
        cost += costinc
        a[i+1] , a[j] = a[j] , a[i+1]
        nexts[nowc] = j
    return cost

main()


Submission Info

Submission Time
Task C - Alternated
User tariaki
Language Python (CPython 3.11.4)
Score 350
Code Size 1178 Byte
Status AC
Exec Time 692 ms
Memory 41080 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 16
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 678 ms 40880 KiB
random_02.txt AC 555 ms 35012 KiB
random_03.txt AC 681 ms 40940 KiB
random_04.txt AC 222 ms 19080 KiB
random_05.txt AC 676 ms 40960 KiB
random_06.txt AC 319 ms 23820 KiB
random_07.txt AC 651 ms 41080 KiB
random_08.txt AC 654 ms 40904 KiB
random_09.txt AC 647 ms 41032 KiB
random_10.txt AC 656 ms 41016 KiB
random_11.txt AC 685 ms 40936 KiB
random_12.txt AC 692 ms 41076 KiB
random_13.txt AC 11 ms 8432 KiB
sample_01.txt AC 10 ms 8428 KiB
sample_02.txt AC 12 ms 8488 KiB
sample_03.txt AC 10 ms 8416 KiB