結果

問題 No.38 赤青白ブロック
ユーザー OUDONOUDON
提出日時 2017-09-07 00:29:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 1,367 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 166,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 01:24:33
合計ジャッジ時間 9,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
4,376 KB
testcase_01 AC 232 ms
4,380 KB
testcase_02 AC 228 ms
4,380 KB
testcase_03 AC 232 ms
4,380 KB
testcase_04 AC 242 ms
4,380 KB
testcase_05 AC 267 ms
4,380 KB
testcase_06 AC 229 ms
4,376 KB
testcase_07 AC 230 ms
4,376 KB
testcase_08 AC 256 ms
4,376 KB
testcase_09 AC 253 ms
4,376 KB
testcase_10 AC 259 ms
4,380 KB
testcase_11 AC 266 ms
4,376 KB
testcase_12 AC 251 ms
4,380 KB
testcase_13 AC 257 ms
4,376 KB
testcase_14 AC 255 ms
4,380 KB
testcase_15 AC 270 ms
4,380 KB
testcase_16 AC 224 ms
4,376 KB
testcase_17 AC 242 ms
4,376 KB
testcase_18 AC 259 ms
4,376 KB
testcase_19 AC 235 ms
4,376 KB
testcase_20 AC 244 ms
4,380 KB
testcase_21 AC 225 ms
4,376 KB
testcase_22 AC 257 ms
4,376 KB
testcase_23 AC 263 ms
4,380 KB
testcase_24 AC 229 ms
4,376 KB
testcase_25 AC 262 ms
4,376 KB
testcase_26 AC 252 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int Kr, Kb;

bool check(string S)
{
    int N = S.size();
    rep(i, N) {
        if (S[i] != 'W') {
            int K = (S[i] == 'R' ? Kr : Kb);
            if (i - K >= 0 && S[i] == S[i - K]) return false;
            if (i + K < N &&  S[i] == S[i + K]) return false;
        }
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> Kr >> Kb;
    string S; cin >> S;
    int ans = 0;

    for (int i=0; i<(1<<20); i++) {
        int cnt = 0;
        string tmp;

        for (auto s : S) {
            if (s == 'W') {
                tmp += s;
            } else {
                if (i>>cnt&1) tmp += s;
                cnt++;
            }
        }

        if (check(tmp)) ans = max(ans, (int)tmp.size());
    }
    cout << ans << endl;
}
0