結果

問題 No.291 黒い文字列
ユーザー 👑 kmjpkmjp
提出日時 2015-10-16 22:37:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 147,008 KB
実行使用メモリ 11,676 KB
最終ジャッジ日時 2023-09-29 00:53:59
合計ジャッジ時間 8,978 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,460 KB
testcase_01 AC 23 ms
11,320 KB
testcase_02 AC 58 ms
11,540 KB
testcase_03 AC 39 ms
11,544 KB
testcase_04 AC 23 ms
11,384 KB
testcase_05 AC 40 ms
11,384 KB
testcase_06 AC 50 ms
11,404 KB
testcase_07 AC 30 ms
11,324 KB
testcase_08 AC 32 ms
11,456 KB
testcase_09 AC 20 ms
11,676 KB
testcase_10 AC 122 ms
11,340 KB
testcase_11 AC 86 ms
11,620 KB
testcase_12 AC 87 ms
11,408 KB
testcase_13 AC 23 ms
11,412 KB
testcase_14 AC 56 ms
11,336 KB
testcase_15 AC 40 ms
11,388 KB
testcase_16 AC 348 ms
11,352 KB
testcase_17 AC 354 ms
11,388 KB
testcase_18 AC 346 ms
11,344 KB
testcase_19 AC 386 ms
11,452 KB
testcase_20 AC 391 ms
11,356 KB
testcase_21 AC 344 ms
11,444 KB
testcase_22 AC 414 ms
11,352 KB
testcase_23 AC 455 ms
11,424 KB
testcase_24 AC 387 ms
11,588 KB
testcase_25 AC 342 ms
11,540 KB
testcase_26 AC 346 ms
11,404 KB
testcase_27 AC 346 ms
11,352 KB
testcase_28 AC 345 ms
11,320 KB
testcase_29 AC 348 ms
11,408 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--)
		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