結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,888 KB
testcase_01 AC 4 ms
4,864 KB
testcase_02 AC 7 ms
4,996 KB
testcase_03 AC 5 ms
4,956 KB
testcase_04 AC 4 ms
4,992 KB
testcase_05 AC 5 ms
4,856 KB
testcase_06 AC 7 ms
4,904 KB
testcase_07 AC 5 ms
4,928 KB
testcase_08 AC 5 ms
4,924 KB
testcase_09 AC 4 ms
4,900 KB
testcase_10 AC 12 ms
4,860 KB
testcase_11 AC 9 ms
5,104 KB
testcase_12 AC 9 ms
4,904 KB
testcase_13 AC 4 ms
4,960 KB
testcase_14 AC 7 ms
4,900 KB
testcase_15 AC 6 ms
4,928 KB
testcase_16 AC 31 ms
4,932 KB
testcase_17 AC 32 ms
5,016 KB
testcase_18 AC 31 ms
5,068 KB
testcase_19 AC 38 ms
4,956 KB
testcase_20 AC 42 ms
5,040 KB
testcase_21 AC 30 ms
4,928 KB
testcase_22 AC 46 ms
4,880 KB
testcase_23 AC 59 ms
4,932 KB
testcase_24 AC 36 ms
4,904 KB
testcase_25 AC 30 ms
4,980 KB
testcase_26 AC 30 ms
4,900 KB
testcase_27 AC 27 ms
5,040 KB
testcase_28 AC 27 ms
4,884 KB
testcase_29 AC 29 ms
4,892 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];

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);
	MINUS(dp);
	int ma=0;
	dp[0][0][0][0][0]=0;
	
	FOR(i,L) {
		int cur=i%2,tar=cur^1;
		memmove(dp[tar],dp[cur],sizeof(dp[tar]));
		FOR(a,21) FOR(b,21) FOR(c,21) FOR(d,21) if(dp[cur][d][c][b][a]>=0) {
			int v=dp[cur][d][c][b][a];
			if(S[i]=='K' || S[i]=='?') if(a<20) dp[tar][d][c][b][a+1] = max(dp[tar][d][c][b][a+1],v);
			if(S[i]=='U' || S[i]=='?') if(b<20 && a) dp[tar][d][c][b+1][a-1] = max(dp[tar][d][c][b+1][a-1],v);
			if(S[i]=='R' || S[i]=='?') if(c<20 && b) dp[tar][d][c+1][b-1][a] = max(dp[tar][d][c+1][b-1][a],v);
			if(S[i]=='O' || S[i]=='?') if(d<20 && c) dp[tar][d+1][c-1][b][a] = max(dp[tar][d+1][c-1][b][a],v);
			if(S[i]=='I' || S[i]=='?') if(d) ma=max(ma,v+1), dp[tar][d-1][c][b][a] = max(dp[tar][d-1][c][b][a],v+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