結果
問題 | No.38 赤青白ブロック |
ユーザー | 184 |
提出日時 | 2015-05-21 09:59:31 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,245 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 83,800 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 04:19:59 |
合計ジャッジ時間 | 1,823 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | int r,b;char s[101];scanf("%d%d%s",&r,&b,s); | ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#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; }