結果

問題 No.291 黒い文字列
ユーザー 👑 kmjpkmjp
提出日時 2015-10-16 22:36:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 725 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 147,064 KB
実行使用メモリ 35,588 KB
最終ジャッジ日時 2023-09-29 00:38:10
合計ジャッジ時間 12,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
35,272 KB
testcase_01 AC 42 ms
35,288 KB
testcase_02 AC 103 ms
35,280 KB
testcase_03 AC 73 ms
35,288 KB
testcase_04 AC 43 ms
35,324 KB
testcase_05 AC 73 ms
35,276 KB
testcase_06 AC 93 ms
35,272 KB
testcase_07 AC 55 ms
35,324 KB
testcase_08 AC 60 ms
35,328 KB
testcase_09 AC 36 ms
35,344 KB
testcase_10 AC 228 ms
35,404 KB
testcase_11 AC 159 ms
35,276 KB
testcase_12 AC 161 ms
35,556 KB
testcase_13 AC 42 ms
35,288 KB
testcase_14 AC 103 ms
35,268 KB
testcase_15 AC 72 ms
35,336 KB
testcase_16 AC 629 ms
35,268 KB
testcase_17 AC 629 ms
35,464 KB
testcase_18 AC 634 ms
35,468 KB
testcase_19 AC 662 ms
35,272 KB
testcase_20 AC 658 ms
35,268 KB
testcase_21 AC 622 ms
35,332 KB
testcase_22 AC 686 ms
35,352 KB
testcase_23 AC 725 ms
35,340 KB
testcase_24 AC 660 ms
35,588 KB
testcase_25 AC 633 ms
35,328 KB
testcase_26 AC 624 ms
35,468 KB
testcase_27 AC 627 ms
35,568 KB
testcase_28 AC 623 ms
35,288 KB
testcase_29 AC 624 ms
35,328 KB
権限があれば一括ダウンロードができます

ソースコード

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;
int 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;
		ZERO(dp[tar]);
		for(a=19;a>=0;a--)
		for(b=20;b>=0;b--)
		for(c=20;c>=0;c--)
		for(d=20;d>=0;d--)
		for(e=20;e>=0;e--) if(dp[cur][a][b][c][d][e]) {
			dp[tar][a][b][c][d][e]=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