結果

問題 No.38 赤青白ブロック
ユーザー togatogatogatoga
提出日時 2015-09-15 19:28:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 285 ms / 5,000 ms
コード長 1,906 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 93,340 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:09:58
合計ジャッジ時間 9,465 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 278 ms
4,380 KB
testcase_01 AC 277 ms
4,380 KB
testcase_02 AC 271 ms
4,376 KB
testcase_03 AC 275 ms
4,380 KB
testcase_04 AC 266 ms
4,380 KB
testcase_05 AC 273 ms
4,380 KB
testcase_06 AC 270 ms
4,376 KB
testcase_07 AC 275 ms
4,380 KB
testcase_08 AC 274 ms
4,376 KB
testcase_09 AC 272 ms
4,376 KB
testcase_10 AC 271 ms
4,380 KB
testcase_11 AC 275 ms
4,376 KB
testcase_12 AC 275 ms
4,380 KB
testcase_13 AC 276 ms
4,376 KB
testcase_14 AC 267 ms
4,376 KB
testcase_15 AC 275 ms
4,380 KB
testcase_16 AC 271 ms
4,380 KB
testcase_17 AC 271 ms
4,376 KB
testcase_18 AC 278 ms
4,380 KB
testcase_19 AC 271 ms
4,380 KB
testcase_20 AC 275 ms
4,380 KB
testcase_21 AC 275 ms
4,380 KB
testcase_22 AC 285 ms
4,376 KB
testcase_23 AC 273 ms
4,376 KB
testcase_24 AC 272 ms
4,384 KB
testcase_25 AC 274 ms
4,380 KB
testcase_26 AC 277 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define mt       make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int Kr,Kb;
string S;
int N;
vector<int> indexs;
bool used[30];
int main(){
  cin >> Kr >> Kb;
  cin >> S;
  N = S.size();
  for (int i = 0; i < N; i++){
    if (S[i] != 'W'){
      indexs.push_back(i);
    }
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << indexs.size()); bit++){
    memset(used, false, sizeof(used));
    
    for (int i = 0; i < N; i++){
      if (S[i] == 'W'){
	used[i] = true;
      }
    }
    for (int i = 0; i < indexs.size(); i++){
      if (bit >> i & 1){
	used[indexs[i]] = true;
      }
    }
    string tmp = "";
    for (int i = 0; i < N; i++){
      if (used[i]){
	tmp += S[i];
      }
    }
    if (tmp.size() <= ans)continue;
    bool ok = true;
    for (int i = 0; i < tmp.size(); i++){
      if (tmp[i] == 'R'){
	if (i - Kr >= 0){
	  ok &= tmp[i - Kr] == 'R' ? false : true;
	}
	if (i + Kr < tmp.size()){
	  ok &= tmp[i + Kr] == 'R' ? false : true;	  
	}
      }
      if (tmp[i] == 'B'){
	if (i - Kb >= 0){
	  ok &= tmp[i - Kb] == 'B' ? false : true;
	}
	if (i + Kb < tmp.size()){
	  ok &= tmp[i + Kb] == 'B' ? false : true;	  
	}
      }
    }
    
    if (ok){
      ans = max(ans, (int)tmp.size());
    }
  }
  cout << ans << endl;
}
0