結果
問題 | No.38 赤青白ブロック |
ユーザー |
![]() |
提出日時 | 2021-02-12 15:52:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 181 ms / 5,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 133 ms |
コンパイル使用メモリ | 81,908 KB |
実行使用メモリ | 76,032 KB |
最終ジャッジ日時 | 2024-07-19 08:59:07 |
合計ジャッジ時間 | 2,495 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
# 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))