結果
問題 | No.38 赤青白ブロック |
ユーザー | szkhts |
提出日時 | 2023-05-14 07:31:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 46 ms / 5,000 ms |
コード長 | 1,080 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-11-29 21:46:02 |
合計ジャッジ時間 | 1,950 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
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 = map(int, input().split()) S = input() print(solve(Kr, Kb, S))