提出 #7404276


ソースコード 拡げる

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 7)


def solve(N: int, K: int, S: str):
    S_list = list(S)
    L_num = 0
    R_num = 0
    small_num = 0
    popular_s = ''
    for i in S_list:
        if i == 'L':
            L_num += 1
        else:
            R_num += 1
    if L_num > R_num:
        popular_s = 'S'
        small_num = R_num
    else:
        popular_s = 'R'
        small_num = L_num

    if small_num <= K:
        print(N - 1)
    else:
        # ちゃんと解く
        a = []
        counter = -1
        result = 0
        before_s = ''
        for i in S_list:
            if i != popular_s:
                counter += 1
            else:
                a.append(counter)
                counter = 0
                if before_s == i:
                    result += 1
            before_s = i
        a.append(counter)

        #print(a)
        #print('tmp result', result)

        a_sorted = sorted(a)

        for i in range(K):
            b = a_sorted.pop()
            result += b + 1
        print(result)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()

提出情報

提出日時
問題 D - Face Produces Unhappiness
ユーザ showwin
言語 PyPy3 (2.4.0)
得点 0
コード長 1643 Byte
結果 RE
実行時間 224 ms
メモリ 49264 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 0 / 400 0 / 0
結果
AC × 16
WA × 3
RE × 5
AC × 3
セット名 テストケース
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20, testcase_21
Sample sample_01, sample_02, sample_03
ケース名 結果 実行時間 メモリ
sample_01 AC 179 ms 38256 KiB
sample_02 AC 168 ms 38256 KiB
sample_03 AC 165 ms 38256 KiB
testcase_01 WA 224 ms 45496 KiB
testcase_02 AC 197 ms 49264 KiB
testcase_03 AC 211 ms 49136 KiB
testcase_04 RE 178 ms 49264 KiB
testcase_05 RE 189 ms 39280 KiB
testcase_06 RE 201 ms 49264 KiB
testcase_07 AC 201 ms 40432 KiB
testcase_08 AC 205 ms 49264 KiB
testcase_09 AC 207 ms 45808 KiB
testcase_10 WA 214 ms 49264 KiB
testcase_11 RE 183 ms 49264 KiB
testcase_12 AC 198 ms 39920 KiB
testcase_13 WA 222 ms 49264 KiB
testcase_14 RE 202 ms 49264 KiB
testcase_15 AC 182 ms 49264 KiB
testcase_16 AC 206 ms 49264 KiB
testcase_17 AC 206 ms 49264 KiB
testcase_18 AC 191 ms 49264 KiB
testcase_19 AC 196 ms 49264 KiB
testcase_20 AC 182 ms 38256 KiB
testcase_21 AC 195 ms 49264 KiB