結果

問題 No.291 黒い文字列
ユーザー 👑 kmjpkmjp
提出日時 2015-10-16 22:40:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,600 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 147,196 KB
実行使用メモリ 11,644 KB
最終ジャッジ日時 2023-09-29 01:06:37
合計ジャッジ時間 5,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,608 KB
testcase_01 AC 8 ms
11,468 KB
testcase_02 AC 12 ms
11,444 KB
testcase_03 AC 10 ms
11,344 KB
testcase_04 AC 8 ms
11,484 KB
testcase_05 AC 9 ms
11,324 KB
testcase_06 AC 11 ms
11,416 KB
testcase_07 AC 9 ms
11,384 KB
testcase_08 AC 9 ms
11,480 KB
testcase_09 AC 8 ms
11,416 KB
testcase_10 AC 20 ms
11,312 KB
testcase_11 AC 16 ms
11,640 KB
testcase_12 AC 15 ms
11,340 KB
testcase_13 AC 8 ms
11,340 KB
testcase_14 AC 11 ms
11,348 KB
testcase_15 AC 10 ms
11,320 KB
testcase_16 AC 128 ms
11,356 KB
testcase_17 AC 131 ms
11,324 KB
testcase_18 AC 127 ms
11,396 KB
testcase_19 AC 155 ms
11,540 KB
testcase_20 AC 159 ms
11,340 KB
testcase_21 AC 121 ms
11,348 KB
testcase_22 AC 185 ms
11,644 KB
testcase_23 AC 216 ms
11,480 KB
testcase_24 AC 156 ms
11,312 KB
testcase_25 AC 125 ms
11,540 KB
testcase_26 AC 124 ms
11,340 KB
testcase_27 AC 118 ms
11,400 KB
testcase_28 AC 119 ms
11,544 KB
testcase_29 AC 119 ms
11,348 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;
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=19;a>=0;a--) if(a*5<L)
		for(b=20;b>=0;b--) if(a*5+4*b<L)
		for(c=20;c>=0;c--) if(a*5+4*b+3*c<L)
		for(d=20;d>=0;d--) if(a*5+4*b+3*c+2*d<L)
		for(e=20;e>=0;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