結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
4,380 KB
testcase_01 AC 238 ms
4,380 KB
testcase_02 AC 235 ms
4,380 KB
testcase_03 AC 250 ms
4,376 KB
testcase_04 AC 238 ms
4,376 KB
testcase_05 AC 262 ms
4,380 KB
testcase_06 AC 236 ms
4,380 KB
testcase_07 AC 232 ms
4,376 KB
testcase_08 AC 277 ms
4,376 KB
testcase_09 AC 253 ms
4,384 KB
testcase_10 AC 282 ms
4,380 KB
testcase_11 AC 271 ms
4,380 KB
testcase_12 AC 257 ms
4,380 KB
testcase_13 AC 275 ms
4,380 KB
testcase_14 AC 252 ms
4,380 KB
testcase_15 AC 257 ms
4,376 KB
testcase_16 AC 238 ms
4,376 KB
testcase_17 AC 240 ms
4,380 KB
testcase_18 AC 251 ms
4,380 KB
testcase_19 AC 245 ms
4,380 KB
testcase_20 AC 245 ms
4,380 KB
testcase_21 AC 224 ms
4,380 KB
testcase_22 AC 247 ms
4,380 KB
testcase_23 AC 285 ms
4,380 KB
testcase_24 AC 234 ms
4,376 KB
testcase_25 AC 253 ms
4,376 KB
testcase_26 AC 248 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int KR, KB;
string s;
bool ok(string t) {
    REP(i,t.size()) {
        if (t[i] == 'R') {
            if (i + KR < t.size() && t[i+KR] == 'R') return false;
            if (i - KR >= 0 && t[i-KR] == 'R') return false;
        } else if (t[i] == 'B') {
            if (i + KB < t.size() && t[i+KB] == 'B') return false;
            if (i - KB >= 0 && t[i-KB] == 'B') return false;
        }
    }
    return true;
}
signed main()
{
    cin>>KR>>KB>>s;
    int maxc = 0;
    REP(r,1<<10) REP(b,1<<10) {
        string t = "";
        int ri = 0;
        int bi = 0;
        REP(i,s.size()) {
            if (s[i] == 'R') {
                if (r & 1<<ri) t += s[i];
                ri++;
            } else if (s[i] == 'B') {
                if (b & 1<<bi) t += s[i];
                bi++;
            } else {
                t+= s[i];
            }
        }
        if (ok(t)) maxc = max(maxc, (int)t.size());
    }
    cout << maxc << endl;
    return 0;
}
0