結果

問題 No.38 赤青白ブロック
ユーザー codershifthcodershifth
提出日時 2015-07-25 07:14:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 259 ms / 5,000 ms
コード長 2,242 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 149,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:08:18
合計ジャッジ時間 9,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
4,380 KB
testcase_01 AC 226 ms
4,376 KB
testcase_02 AC 244 ms
4,380 KB
testcase_03 AC 241 ms
4,376 KB
testcase_04 AC 229 ms
4,380 KB
testcase_05 AC 251 ms
4,376 KB
testcase_06 AC 235 ms
4,376 KB
testcase_07 AC 237 ms
4,380 KB
testcase_08 AC 253 ms
4,376 KB
testcase_09 AC 241 ms
4,380 KB
testcase_10 AC 252 ms
4,380 KB
testcase_11 AC 248 ms
4,380 KB
testcase_12 AC 254 ms
4,380 KB
testcase_13 AC 249 ms
4,376 KB
testcase_14 AC 253 ms
4,376 KB
testcase_15 AC 234 ms
4,376 KB
testcase_16 AC 215 ms
4,380 KB
testcase_17 AC 233 ms
4,380 KB
testcase_18 AC 240 ms
4,380 KB
testcase_19 AC 229 ms
4,380 KB
testcase_20 AC 241 ms
4,380 KB
testcase_21 AC 228 ms
4,380 KB
testcase_22 AC 222 ms
4,380 KB
testcase_23 AC 259 ms
4,376 KB
testcase_24 AC 234 ms
4,380 KB
testcase_25 AC 257 ms
4,384 KB
testcase_26 AC 236 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class RedBlueWhiteBlocks {
public:
    void solve(void) {
            int Kr,Kb;
            cin>>Kr>>Kb;
            string S;
            cin>>S;
            int N = S.length();
            vector<int> ri;
            vector<int> bi;

            // 赤・青のブロックの最大数はそれぞれ 2^20 なんで全探索すればよい
            // それぞれの色のインデックスを格納しておく
            REP(i, N)
            {
                if (S[i] == 'R')
                    ri.push_back(i);
                else if (S[i] == 'B')
                    bi.push_back(i);
            }
            assert(ri.size()==10);
            assert(bi.size()==10);

            vector<int> badr;
            vector<int> badb;
            int maxLen = 0;
            // 取り除くインデクスごとに回る
            for (int r = 0; r < (1<<10); ++r)
            for (int b = 0; b < (1<<10); ++b)
            {
                string tmp(S);
                REP(i,10)
                {
                    if (r & (1<<i))
                        tmp[ri[i]] = ' ';
                    if (b & (1<<i))
                        tmp[bi[i]] = ' ';
                }
                // 空白除去
                tmp.erase (remove(RANGE(tmp), ' '), tmp.end());

                // check
                bool ok = true;
                int n = tmp.size();
                REP(i,n)
                {
                    if ( (tmp[i] == 'R' && i-Kr >= 0 && tmp[i-Kr] == 'R') ||
                         (tmp[i] == 'B' && i-Kb >= 0 && tmp[i-Kb] == 'B') )
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                    maxLen = max(maxLen, n);
            }
            cout<<maxLen<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new RedBlueWhiteBlocks();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0