結果

問題 No.38 赤青白ブロック
コンテスト
ユーザー hogeover30
提出日時 2015-02-04 03:47:49
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 962 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,000 ms
コンパイル使用メモリ 170,852 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:01:18
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool ok(const string& s, char c, int k)
{
    for(int i=0;i<s.size();++i)
        if (s[i]==c and ((i+k<s.size() and s[i+k]==c) or (i-k>=0 and s[i-k]==c)))
            return false;
    return true;
}

int main()
{
    int r, b;
    string s;
    while (cin>>r>>b>>s) {
        int res=0;
        vector<int> x;
        for(int i=0;i<s.size();++i) if (s[i]!='W') x.push_back(i);
        for(int i=0;i<(1<<20);++i) {
            if (s.size()-__builtin_popcount(i)<=res) continue;
            string t;
            vector<int> v;
            for(int j=0;j<20;++j) if (i&(1<<j)) v.push_back(x[j]);
            for(int j=0,p=0;j<s.size();++j) {
                if (p>=v.size() or j!=v[p] )
                    t+=s[j];
                else
                    ++p;
            }
            if (ok(t, 'R', r) and ok(t, 'B', b)) res=t.size();
        }
        cout<<res<<endl;
    }
}
0