結果

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

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:9: error: ‘vector’ was not declared in this scope
   20 |         vector<int> x;
      |         ^~~~~~
main.cpp:4:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | using namespace std;
main.cpp:20:16: error: expected primary-expression before ‘int’
   20 |         vector<int> x;
      |                ^~~
main.cpp:21:52: error: ‘x’ was not declared in this scope
   21 |         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’
   25 |             vector<int> v;
      |                    ^~~
main.cpp:26:49: error: ‘v’ was not declared in this scope
   26 |             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
   26 |             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
   28 |                 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