結果

問題 No.291 黒い文字列
ユーザー chocoruskchocorusk
提出日時 2019-01-12 11:59:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 2,055 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 96,724 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2023-08-22 15:44:13
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,420 KB
testcase_01 AC 2 ms
5,492 KB
testcase_02 AC 3 ms
9,676 KB
testcase_03 AC 2 ms
9,572 KB
testcase_04 AC 2 ms
7,540 KB
testcase_05 AC 3 ms
9,556 KB
testcase_06 AC 3 ms
9,888 KB
testcase_07 AC 2 ms
5,716 KB
testcase_08 AC 3 ms
7,560 KB
testcase_09 AC 2 ms
5,400 KB
testcase_10 AC 5 ms
17,932 KB
testcase_11 AC 3 ms
13,896 KB
testcase_12 AC 4 ms
13,632 KB
testcase_13 AC 1 ms
5,500 KB
testcase_14 AC 3 ms
9,724 KB
testcase_15 AC 3 ms
7,548 KB
testcase_16 AC 31 ms
37,076 KB
testcase_17 AC 32 ms
37,732 KB
testcase_18 AC 31 ms
37,268 KB
testcase_19 AC 38 ms
38,056 KB
testcase_20 AC 41 ms
37,060 KB
testcase_21 AC 28 ms
38,784 KB
testcase_22 AC 43 ms
37,892 KB
testcase_23 AC 56 ms
38,244 KB
testcase_24 AC 35 ms
37,812 KB
testcase_25 AC 30 ms
37,800 KB
testcase_26 AC 30 ms
37,656 KB
testcase_27 AC 27 ms
37,284 KB
testcase_28 AC 28 ms
37,576 KB
testcase_29 AC 31 ms
38,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int dp[2][101][51][34][26];
	string s; cin>>s;
	int n=s.size();
	for(int j=0; j<=n; j++){
		for(int k=0; j+2*k<=n; k++){
			for(int l=0; j+2*k+3*l<=n; l++){
				for(int m=0; j+2*k+3*l+4*m<=n; m++){
					dp[0][j][k][l][m]=dp[1][j][k][l][m]=-1;
				}
			}
		}
	}
	dp[0][0][0][0][0]=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<=i; j++){
			for(int k=0; j+2*k<=i; k++){
				for(int l=0; j+2*k+3*l<=i; l++){
					for(int m=0; j+2*k+3*l+4*m<=i; m++){
						dp[(i&1)^1][j][k][l][m]=dp[i&1][j][k][l][m];
					}
				}
			}
		}
		for(int j=0; j<=i; j++){
			for(int k=0; 2*k+j<=i; k++){
				for(int l=0; j+2*k+3*l<=i; l++){
					for(int m=0; j+2*k+3*l+4*m<=i; m++){
						if(dp[i&1][j][k][l][m]<0) continue;
						if(s[i]=='K' || s[i]=='?'){
							dp[(i&1)^1][j+1][k][l][m]=max(dp[i&1][j][k][l][m], dp[(i&1)^1][j+1][k][l][m]);
						}
						if((s[i]=='U' || s[i]=='?') && j>0){
							dp[(i&1)^1][j-1][k+1][l][m]=max(dp[i&1][j][k][l][m], dp[(i&1)^1][j-1][k+1][l][m]);
						}
						if((s[i]=='R' || s[i]=='?') && k>0){
							dp[(i&1)^1][j][k-1][l+1][m]=max(dp[i&1][j][k][l][m], dp[(i&1)^1][j][k-1][l+1][m]);
						}
						if((s[i]=='O' || s[i]=='?') && l>0){
							dp[(i&1)^1][j][k][l-1][m+1]=max(dp[i&1][j][k][l][m], dp[(i&1)^1][j][k][l-1][m+1]);
						}
						if((s[i]=='I' || s[i]=='?') && m>0){
							dp[(i&1)^1][j][k][l][m-1]=max(dp[i&1][j][k][l][m]+1, dp[(i&1)^1][j][k][l][m-1]);
						}
					}
				}
			}
		}
	}
	int ans=0;
	for(int j=0; j<=n; j++){
		for(int k=0; j+2*k<=n; k++){
			for(int l=0; j+2*k+3*l<=n; l++){
				for(int m=0; j+2*k+3*l+4*m<=n; m++){
					ans=max(ans, dp[n&1][j][k][l][m]);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
0