結果

問題 No.291 黒い文字列
ユーザー 👑 kmjpkmjp
提出日時 2015-10-16 22:42:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 2,925 ms
コンパイル使用メモリ 147,292 KB
実行使用メモリ 11,668 KB
最終ジャッジ日時 2023-09-29 01:15:15
合計ジャッジ時間 6,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,332 KB
testcase_01 AC 9 ms
11,344 KB
testcase_02 AC 12 ms
11,540 KB
testcase_03 AC 10 ms
11,344 KB
testcase_04 AC 9 ms
11,320 KB
testcase_05 AC 11 ms
11,516 KB
testcase_06 AC 11 ms
11,324 KB
testcase_07 AC 9 ms
11,320 KB
testcase_08 AC 10 ms
11,448 KB
testcase_09 AC 8 ms
11,324 KB
testcase_10 AC 21 ms
11,312 KB
testcase_11 AC 15 ms
11,324 KB
testcase_12 AC 16 ms
11,384 KB
testcase_13 AC 8 ms
11,340 KB
testcase_14 AC 12 ms
11,324 KB
testcase_15 AC 10 ms
11,364 KB
testcase_16 WA -
testcase_17 AC 172 ms
11,564 KB
testcase_18 WA -
testcase_19 AC 208 ms
11,332 KB
testcase_20 AC 217 ms
11,348 KB
testcase_21 AC 79 ms
11,328 KB
testcase_22 AC 211 ms
11,472 KB
testcase_23 AC 262 ms
11,316 KB
testcase_24 AC 201 ms
11,340 KB
testcase_25 AC 100 ms
11,340 KB
testcase_26 AC 116 ms
11,316 KB
testcase_27 AC 66 ms
11,476 KB
testcase_28 AC 71 ms
11,388 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int L;
string S;
char dp[2][21][21][21][21][21];

void solve() {
	int i,j,k,l,r,x,y; string s;
	int a,b,c,d,e;
	cin>>S;
	L=S.size();
	
	ZERO(dp);
	int ma=0;
	dp[0][0][0][0][0][0]=1;
	
	FOR(i,L) {
		int cur=i%2,tar=cur^1;
		memmove(dp[tar],dp[cur],sizeof(dp[tar]));
		for(a=0;a*5<=i;a++)
		for(b=0;a*5+b*4<=i;b++)
		for(c=0;a*5+b*4+c*3<=i;c++)
		for(d=0;a*5+b*4+c*3+d*2<=i;d++)
		for(e=0;a*5+b*4+c*3+d*2+e<=i;e++) if(dp[cur][a][b][c][d][e]) {
			if(S[i]=='K' || S[i]=='?') if(e<20) dp[tar][a][b][c][d][e+1] = 1;
			if(S[i]=='U' || S[i]=='?') if(d<20 && e) dp[tar][a][b][c][d+1][e-1] = 1;
			if(S[i]=='R' || S[i]=='?') if(c<20 && d) dp[tar][a][b][c+1][d-1][e] = 1;
			if(S[i]=='O' || S[i]=='?') if(b<20 && c) dp[tar][a][b+1][c-1][d][e] = 1;
			if(S[i]=='I' || S[i]=='?') if(a<20 && b) dp[tar][a+1][b-1][c][d][e] = 1, ma=max(ma,a+1);
		}
		
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0