結果

問題 No.38 赤青白ブロック
ユーザー pessimist
提出日時 2024-10-24 04:01:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 677 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 192,668 KB
最終ジャッジ日時 2025-02-24 22:36:44
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int a, b, ans = 0;
string s, t;
void dfs(int cur){
  if(cur == s.size()){
    ans = max(ans, (int)t.size());
    return;
  }
  if(s[cur] == 'W'){
    t += 'W';
    dfs(cur + 1);
    t.pop_back();
  } else{
    dfs(cur + 1);
    if(s[cur] == 'R'){
      if(cur - a < 0 || *(t.end() - a) != 'R'){
        t += 'R';
        dfs(cur + 1);
        t.pop_back();
      }
    } else{
      if(cur - b < 0 || *(t.end() - b) != 'B'){
        t += 'B';
        dfs(cur + 1);
        t.pop_back();
      }
    }
  }
}
int main(){
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> a >> b >> s;
  dfs(0);
  cout << ans << endl;
  return 0;
}
0