結果

問題 No.38 赤青白ブロック
ユーザー codershifthcodershifth
提出日時 2015-07-25 07:09:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,783 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 149,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 04:41:42
合計ジャッジ時間 10,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 275 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 263 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 267 ms
4,376 KB
testcase_08 AC 296 ms
4,376 KB
testcase_09 AC 265 ms
4,376 KB
testcase_10 AC 292 ms
4,380 KB
testcase_11 AC 295 ms
4,376 KB
testcase_12 AC 285 ms
4,380 KB
testcase_13 AC 292 ms
4,376 KB
testcase_14 AC 286 ms
4,380 KB
testcase_15 AC 274 ms
4,376 KB
testcase_16 AC 251 ms
4,376 KB
testcase_17 AC 265 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 270 ms
4,376 KB
testcase_20 AC 269 ms
4,376 KB
testcase_21 AC 261 ms
4,380 KB
testcase_22 AC 248 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 296 ms
4,380 KB
testcase_26 AC 272 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();
                vector<int> flag(n,0); // 赤 1 青 -1
                REP(i,n)
                {
                    if (tmp[i] == 'R')
                    {
                        if (flag[i] == 1)
                        {
                            ok = false;
                            break;
                        }
                        if (i+Kr < n)
                            flag[i+Kr] = 1;
                        flag[i] = 1;
                    }
                    else if (tmp[i] == 'B')
                    {
                        if (flag[i] == -1)
                        {
                            ok = false;
                            break;
                        }
                        if (i+Kb < n)
                            flag[i+Kb] = -1;
                        flag[i] = -1;
                    }
                }
                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