結果

問題 No.38 赤青白ブロック
ユーザー mkawa2
提出日時 2020-01-08 18:31:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 915 ms / 5,000 ms
コード長 793 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-23 03:02:47
合計ジャッジ時間 13,870 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
def MI(): return map(int, sys.stdin.readline().split())

def ok(bit):
    a = []
    for i, c in enumerate(s):
        if c == "R":
            if bit & 1:
                if len(a) >= kr and a[-kr] == 1: return False
                a.append(1)
            bit >>= 1
        elif c == "B":
            if bit & 1:
                if len(a) >= kb and a[-kb] == 2: return False
                a.append(2)
            bit >>= 1
        else:
            a.append(0)
    return True

def main():
    popcut = lambda x: bin(x).count("1")
    ans = 0
    # 1がたっている所を残す
    for bit in range(1 << 20):
        p = popcut(bit)
        if p <= ans: continue
        if ok(bit): ans = p
    print(ans+10)

kr, kb = MI()
s = input()
main()
0