結果
問題 | No.2553 Holidays |
ユーザー | Seed57_cash |
提出日時 | 2023-11-21 19:39:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 2,448 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 81,848 KB |
実行使用メモリ | 78,080 KB |
最終ジャッジ日時 | 2024-09-26 10:20:47 |
合計ジャッジ時間 | 5,234 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
76,544 KB |
testcase_01 | AC | 75 ms
72,576 KB |
testcase_02 | AC | 74 ms
72,644 KB |
testcase_03 | AC | 83 ms
74,752 KB |
testcase_04 | AC | 74 ms
72,832 KB |
testcase_05 | AC | 74 ms
71,552 KB |
testcase_06 | AC | 70 ms
71,040 KB |
testcase_07 | AC | 74 ms
71,552 KB |
testcase_08 | AC | 76 ms
73,600 KB |
testcase_09 | AC | 67 ms
69,760 KB |
testcase_10 | AC | 89 ms
77,952 KB |
testcase_11 | AC | 89 ms
78,080 KB |
testcase_12 | AC | 89 ms
78,080 KB |
testcase_13 | AC | 87 ms
78,080 KB |
testcase_14 | AC | 91 ms
77,928 KB |
testcase_15 | AC | 83 ms
77,568 KB |
testcase_16 | AC | 70 ms
69,248 KB |
testcase_17 | AC | 78 ms
72,576 KB |
testcase_18 | AC | 78 ms
72,320 KB |
testcase_19 | AC | 68 ms
69,120 KB |
testcase_20 | AC | 74 ms
72,320 KB |
testcase_21 | AC | 74 ms
72,448 KB |
testcase_22 | AC | 69 ms
70,144 KB |
testcase_23 | AC | 64 ms
68,608 KB |
testcase_24 | AC | 75 ms
72,576 KB |
testcase_25 | AC | 73 ms
71,808 KB |
testcase_26 | AC | 72 ms
71,424 KB |
testcase_27 | AC | 80 ms
77,656 KB |
testcase_28 | AC | 73 ms
71,808 KB |
testcase_29 | AC | 71 ms
71,808 KB |
testcase_30 | AC | 40 ms
52,736 KB |
testcase_31 | AC | 39 ms
52,352 KB |
testcase_32 | AC | 38 ms
52,096 KB |
testcase_33 | AC | 39 ms
52,864 KB |
testcase_34 | AC | 39 ms
52,352 KB |
testcase_35 | AC | 40 ms
52,992 KB |
testcase_36 | AC | 39 ms
52,608 KB |
testcase_37 | AC | 39 ms
52,096 KB |
testcase_38 | AC | 41 ms
52,096 KB |
testcase_39 | AC | 42 ms
52,608 KB |
testcase_40 | AC | 40 ms
52,272 KB |
testcase_41 | AC | 40 ms
52,480 KB |
testcase_42 | AC | 39 ms
52,608 KB |
testcase_43 | AC | 40 ms
52,224 KB |
testcase_44 | AC | 41 ms
52,480 KB |
testcase_45 | AC | 41 ms
52,352 KB |
testcase_46 | AC | 41 ms
52,608 KB |
testcase_47 | AC | 43 ms
52,096 KB |
testcase_48 | AC | 42 ms
52,480 KB |
testcase_49 | AC | 42 ms
52,224 KB |
testcase_50 | AC | 41 ms
52,480 KB |
testcase_51 | AC | 42 ms
52,224 KB |
testcase_52 | AC | 41 ms
52,208 KB |
testcase_53 | AC | 41 ms
52,480 KB |
testcase_54 | AC | 41 ms
51,968 KB |
testcase_55 | AC | 40 ms
52,480 KB |
testcase_56 | AC | 40 ms
52,400 KB |
testcase_57 | AC | 40 ms
52,352 KB |
ソースコード
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]) if i % 2 == 1: res += i * d else: res += (i - 1) * d mm -= d * ((i + 1) // 2) if d < type_2[i] and mm > 0: 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 assert solve(6, 4, "------") == 6 assert solve(6, 3, "------") == 5 assert solve(6, 2, "------") == 3 assert solve(6, 1, "------") == 1 assert solve(6, 0, "------") == 0 if __name__ == "__main__": test() main()