結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-12-14 18:59:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,168 bytes |
| コンパイル時間 | 2,217 ms |
| コンパイル使用メモリ | 212,504 KB |
| 最終ジャッジ日時 | 2025-01-06 19:05:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 TLE * 1 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
string s;
cin>>s;
int n=s.size();
using T = tuple<int, int, int, int>;
vector<map<T, int> > dp(n+1);
dp[0][T(0,0,0,0)]=0;
for(int i=0;i<n;i++){
for(auto p:dp[i]){
T t=p.first;
int res=p.second;
int a,b,c,d;
tie(a,b,c,d)=t;
chmax(dp[i+1][T(a,b,c,d)],res);
if(s[i]=='K'||s[i]=='?'){
chmax(dp[i+1][T(a+1,b,c,d)],res);
}
if(s[i]=='U'||s[i]=='?'){
if(a) chmax(dp[i+1][T(a-1,b+1,c,d)],res);
}
if(s[i]=='R'||s[i]=='?'){
if(b) chmax(dp[i+1][T(a,b-1,c+1,d)],res);
}
if(s[i]=='O'||s[i]=='?'){
if(c) chmax(dp[i+1][T(a,b,c-1,d+1)],res);
}
if(s[i]=='I'||s[i]=='?'){
if(d) chmax(dp[i+1][T(a,b,c,d-1)],res+1);
}
}
}
int ans=0;
for(int i=0;i<=n;i++)
for(auto p:dp[i])
chmax(ans,p.second);
cout<<ans<<endl;
return 0;
}
beet