結果

問題 No.38 赤青白ブロック
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-04 00:05:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,150 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-25 01:08:26
合計ジャッジ時間 1,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,952 KB
testcase_01 AC 29 ms
8,764 KB
testcase_02 AC 15 ms
7,852 KB
testcase_03 AC 15 ms
7,952 KB
testcase_04 AC 15 ms
7,776 KB
testcase_05 AC 15 ms
7,884 KB
testcase_06 AC 17 ms
8,380 KB
testcase_07 AC 18 ms
7,824 KB
testcase_08 AC 16 ms
7,920 KB
testcase_09 AC 18 ms
8,476 KB
testcase_10 AC 15 ms
7,820 KB
testcase_11 AC 16 ms
7,820 KB
testcase_12 AC 15 ms
7,772 KB
testcase_13 AC 15 ms
7,948 KB
testcase_14 AC 15 ms
7,856 KB
testcase_15 AC 16 ms
7,888 KB
testcase_16 AC 19 ms
8,272 KB
testcase_17 AC 16 ms
7,852 KB
testcase_18 AC 16 ms
8,376 KB
testcase_19 AC 16 ms
7,992 KB
testcase_20 AC 16 ms
7,888 KB
testcase_21 AC 16 ms
7,956 KB
testcase_22 AC 29 ms
8,548 KB
testcase_23 AC 16 ms
7,800 KB
testcase_24 AC 17 ms
8,436 KB
testcase_25 AC 15 ms
7,892 KB
testcase_26 AC 15 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    Kr, Kb = map(int, input().split())
    S = input()
    return Kr, Kb, S

def solve(Kr, Kb, S):
    if is_valid(S, Kr, Kb):
        return len(S)
    strings = set([S])
    for i in range(20):
        new_strings = set()
        for string in strings:
            for i, c in enumerate(string):
                if c == 'W':
                    continue
                new_string = string[:i] + string[i+1:]
                if new_string in new_strings:
                    continue
                if is_valid(new_string, Kr, Kb):
                    return len(new_string)
                new_strings.add(new_string)
        strings = new_strings

def is_valid(S, Kr, Kb):
    n = len(S)
    for i, c in enumerate(S):
        if c == 'B':
            if i >= Kb and S[i - Kb] == 'B':
                return False
            if i + Kb < n and S[i + Kb] == 'B':
                return False
        elif c == 'R':
            if i >= Kr and S[i - Kr] == 'R':
                return False
            if i + Kr < n and S[i + Kr] == 'R':
                return False
    return True

Kr, Kb, S = read_data()
print(solve(Kr, Kb, S))
0