結果

問題 No.38 赤青白ブロック
ユーザー maninimanini
提出日時 2021-02-12 15:52:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 243 ms / 5,000 ms
コード長 1,669 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 77,816 KB
最終ジャッジ日時 2023-09-26 14:47:54
合計ジャッジ時間 4,671 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,956 KB
testcase_01 AC 173 ms
77,816 KB
testcase_02 AC 98 ms
76,588 KB
testcase_03 AC 80 ms
75,928 KB
testcase_04 AC 77 ms
71,376 KB
testcase_05 AC 75 ms
71,116 KB
testcase_06 AC 109 ms
77,360 KB
testcase_07 AC 98 ms
76,880 KB
testcase_08 AC 74 ms
71,444 KB
testcase_09 AC 101 ms
77,276 KB
testcase_10 AC 74 ms
71,228 KB
testcase_11 AC 75 ms
71,572 KB
testcase_12 AC 75 ms
71,440 KB
testcase_13 AC 73 ms
71,572 KB
testcase_14 AC 76 ms
71,496 KB
testcase_15 AC 85 ms
76,332 KB
testcase_16 AC 110 ms
77,184 KB
testcase_17 AC 81 ms
75,944 KB
testcase_18 AC 94 ms
76,812 KB
testcase_19 AC 92 ms
76,716 KB
testcase_20 AC 87 ms
76,416 KB
testcase_21 AC 84 ms
76,028 KB
testcase_22 AC 243 ms
77,148 KB
testcase_23 AC 77 ms
71,096 KB
testcase_24 AC 97 ms
76,548 KB
testcase_25 AC 80 ms
75,964 KB
testcase_26 AC 83 ms
76,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding:UTF-8
import sys
from itertools import combinations

MOD = 10 ** 9 + 7
INF = float('inf')

# 前処理なし
def comb(n, k):
    if n < k:
        return 0
    elif n < 0 or k < 0:
        return 0
    a = 1
    for i in range(k):
        a = a * (n - i)
    b = 1
    for i in range(1, k+1):
        b = b * i
    return a // b

Kr, Kb = list(map(int, input().split()))     # スペース区切り連続数字
S = input()     # 文字列

BRs = []
for i in range(30):
    if S[i] != "W":
        BRs.append(i)

for i in range(21):
    possible_i = False
    Nt = 30 - i

    for r in combinations(BRs, i):
        nums = set(r)
        Stmp = []
        for j in range(30):
            if j not in nums:
                Stmp.append(S[j])

        possible = True
        for j in range(Nt):
            if Stmp[j] == "W":
                continue

            elif Stmp[j] == "R":
                if j - Kr >= 0:
                    if Stmp[j - Kr] == "R":
                        possible = False
                        break
                if j + Kr <= Nt - 1:
                    if Stmp[j + Kr] == "R":
                        possible = False
                        break

            elif Stmp[j] == "B":
                if j - Kb >= 0:
                    if Stmp[j - Kb] == "B":
                        possible = False
                        break
                if j + Kb <= Nt - 1:
                    if Stmp[j + Kb] == "B":
                        possible = False
                        break

        if possible:
            possible_i = True
            break

    if possible_i:
        res = Nt
        break

print("{}".format(res))
0