結果

問題 No.2553 Holidays
ユーザー Seed57_cashSeed57_cash
提出日時 2023-11-21 19:23:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,175 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,704 KB
最終ジャッジ日時 2023-11-25 12:30:44
合計ジャッジ時間 4,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 65 ms
72,476 KB
testcase_02 AC 66 ms
72,476 KB
testcase_03 AC 74 ms
74,576 KB
testcase_04 WA -
testcase_05 AC 63 ms
70,416 KB
testcase_06 WA -
testcase_07 AC 64 ms
70,416 KB
testcase_08 AC 67 ms
72,512 KB
testcase_09 AC 62 ms
70,416 KB
testcase_10 AC 78 ms
77,704 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 78 ms
77,704 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 59 ms
70,432 KB
testcase_20 AC 67 ms
75,748 KB
testcase_21 AC 65 ms
70,404 KB
testcase_22 AC 61 ms
70,404 KB
testcase_23 AC 57 ms
68,312 KB
testcase_24 AC 66 ms
75,748 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 39 ms
53,460 KB
testcase_31 AC 39 ms
53,460 KB
testcase_32 AC 40 ms
53,460 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 38 ms
53,460 KB
testcase_41 AC 39 ms
53,460 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 38 ms
53,460 KB
testcase_45 AC 38 ms
53,460 KB
testcase_46 WA -
testcase_47 AC 38 ms
53,460 KB
testcase_48 AC 39 ms
53,460 KB
testcase_49 WA -
testcase_50 AC 40 ms
53,460 KB
testcase_51 AC 39 ms
53,460 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, m, s):
    # o---x or x---o
    # o---o
    # x---x
    # がそれぞれ長さいくつが何個あるか数える
    type_0 = [0] * (n + 1)
    type_1 = [0] * (n + 1)
    type_2 = [0] * (n + 1)
    left = "x"
    c = 0
    res = 0
    xc = 0
    for i in range(n + 1):
        if i < n:
            a = s[i]
            if a == "x":
                xc += 1
        else:
            a = "x"
        if a == "o":
            res += 1
        if a == "-":
            c += 1
        else:
            if a == "x" and left == "x":
                type_2[c] += 1
            elif a == "o" and left == "o":
                type_1[c] += 1
            else:
                type_0[c] += 1
            c = 0
            left = a
    # そもそも休み
    res += type_1[1]
    # print(res)
    # print(type_0)
    # print(type_1)
    # print(type_2)
    # 貪欲
    mm = m
    for i in range(3, n + 1, 2):
        d = min(mm // (i // 2), type_1[i])
        res += i * d
        mm -= d * (i // 2)
        if d < type_1[i]:
            res += 2 * mm
            mm = 0
            break
    # 2倍増えるところ
    twos = 0
    for i in range(2, n + 1, 2):
        twos += type_1[i] * (i // 2)
    for i in range(n + 1):
        twos += type_0[i] * (i // 2)
    # print(twos)

    if mm > twos:
        res += 2 * twos
        mm -= twos
    else:
        res += 2 * mm
        mm = 0

    # 2倍弱増えるところ
    for i in range(n, 2, -1):
        d = min(mm // ((i + 1) // 2), type_2[i])
        res += i * d
        mm -= d * ((i + 1) // 2)
        if d < type_2[i]:
            res += 2 * mm - 1
            mm = 0
            break

    # それでも余った場合
    res_max = n - xc
    res = min(res + mm, res_max)
    # print(res)
    return res


def main():
    n, m = map(int, input().split())
    s = input()
    res = solve(n, m, s)
    print(res)


def test():
    assert solve(8, 2, "x-o----x") == 5
    assert solve(20, 5, "xo--x-o--o--------ox") == 14
    assert solve(5, 0, "xo-ox") == 3
    assert solve(20, 20, "xo--x-o--o--------ox") == 17
    assert solve(5, 5, "xo-ox") == 3


if __name__ == "__main__":
    test()
    main()
0