結果

問題 No.2553 Holidays
ユーザー 👑 rin204
提出日時 2024-09-15 15:33:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 81,408 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2024-09-15 15:33:52
合計ジャッジ時間 5,753 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
S = input()
S = "x" + S + "x"

ans = S.count("o")
S = S.split("o")

A = []
two = 0
one = 0
B = []
for T in S:
    if "x" not in T:
        le = len(T)
        if le == 1:
            ans += 1
        elif le % 2 == 1:
            A.append(le // 2)
        else:
            two += le // 2
    else:
        row = T.split("x")
        for i in range(len(row)):
            le = len(row[i])
            if le == 0:
                continue
            if i == 0 or i == len(row) - 1:
                two += le // 2
                if le % 2 == 1:
                    one += 1
            else:
                B.append(le)


C = []
A.sort()
for a in A:
    C += [2] * (a - 1)
    C += [3]

C += [2] * two
B.sort(reverse=True)
for b in B:
    C += [1]
    if b % 2 == 0:
        b -= 1
        one += 1
    C += [2] * (b // 2)

C += [1] * one

ans += sum(C[:m])
print(ans)
0