結果

問題 No.38 赤青白ブロック
ユーザー 184184
提出日時 2015-05-21 09:59:31
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,245 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 85,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 08:36:48
合計ジャッジ時間 2,613 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <functional>
#include <iostream>


using namespace std;
 
//namaega184 
 
int main(){
	 
	int r,b;char s[101];scanf("%d%d%s",&r,&b,s); 
	set<string> st;st.insert(string(s));
	auto cmparetor=[](string &a,string &b){return a.size()<b.size();};
	priority_queue<string,vector<string>,decltype(cmparetor)> pq(cmparetor);pq.push(string(s));
	int change=1;
	int ans=0;
	auto ischange=[&](string str,int pos,int npos){
		str.erase(str.begin()+pos+npos);
		//printf("%s\n",str.c_str());
		if(st.find(str)==st.end()){ 
			pq.push(str);st.insert(str);
		}
		return 1;
	};
	while(change){
		change = 0;
		string tmp;
		for(int i=0;i<pq.size();i++){
			tmp=pq.top();pq.pop(); 
			change=0;
			for(int j=0;j<tmp.size();j++){
				if(tmp[j]=='R'){
					if(j+r<tmp.size()&&tmp[j+r]=='R')change|=ischange(tmp,j,r);
					if(j-r>=0&&tmp[j-r]=='R')change|=ischange(tmp,j,-r);
					 
				}
				else if(tmp[j]=='B'){
					if(j+b<tmp.size()&&tmp[j+b]=='B')change|=ischange(tmp,j,b);
					if(j-b>=0&&tmp[j-b]=='B')change|=ischange(tmp,j,-b);
				}
			}
			if(change==0)break;
		}
		ans=tmp.size();
	}
	printf("%d\n",ans);  
	return 0; 
}
0