結果

問題 No.38 赤青白ブロック
コンテスト
ユーザー 184
提出日時 2015-05-21 09:59:31
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,245 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 893 ms
コンパイル使用メモリ 104,940 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-27 14:52:07
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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