結果

問題 No.38 赤青白ブロック
ユーザー hogeover30hogeover30
提出日時 2015-02-04 03:47:49
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 962 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 53,164 KB
最終ジャッジ日時 2023-08-25 00:59:21
合計ジャッジ時間 754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:9: error: ‘vector’ was not declared in this scope
         vector<int> x;
         ^~~~~~
main.cpp:20:9: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:4:1:
+#include <vector>
 using namespace std;
main.cpp:20:9:
         vector<int> x;
         ^~~~~~
main.cpp:20:16: error: expected primary-expression before ‘int’
         vector<int> x;
                ^~~
main.cpp:21:52: error: ‘x’ was not declared in this scope
         for(int i=0;i<s.size();++i) if (s[i]!='W') x.push_back(i);
                                                    ^
main.cpp:25:20: error: expected primary-expression before ‘int’
             vector<int> v;
                    ^~~
main.cpp:26:49: error: ‘v’ was not declared in this scope
             for(int j=0;j<20;++j) if (i&(1<<j)) v.push_back(x[j]);
                                                 ^
main.cpp:26:61: error: ‘x’ was not declared in this scope
             for(int j=0;j<20;++j) if (i&(1<<j)) v.push_back(x[j]);
                                                             ^
main.cpp:28:24: error: ‘v’ was not declared in this scope
                 if (p>=v.size() or j!=v[p] )
                        ^

ソースコード

diff #

#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