結果
| 問題 |
No.291 黒い文字列
|
| ユーザー |
|
| 提出日時 | 2022-08-24 11:13:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 2,723 bytes |
| コンパイル時間 | 1,912 ms |
| コンパイル使用メモリ | 179,932 KB |
| 実行使用メモリ | 5,760 KB |
| 最終ジャッジ日時 | 2024-10-11 20:57:41 |
| 合計ジャッジ時間 | 3,673 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
vector4d(int,dp,21,21,21,21,-(1<<30));
dp[0][0][0][0] = 0;
for(int i = 0; i < n; i++){
vector4d(int,ndp,21,21,21,21,-(1<<30));
if(s[i] == '?'){
for(int a = 0; a <= 20; a++){
for(int b = 0; b <= a; b++){
for(int c = 0; c <= b; c++){
for(int d = 0; d <= c; d++){
ndp[a][b][c][d] = max(ndp[a][b][c][d], dp[a][b][c][d]);
if(a + 1 <= 20)ndp[a + 1][b][c][d] = max(ndp[a + 1][b][c][d], dp[a][b][c][d]);
if(b + 1 <= a)ndp[a][b + 1][c][d] = max(ndp[a][b + 1][c][d], dp[a][b][c][d]);
if(c + 1 <= b)ndp[a][b][c + 1][d] = max(ndp[a][b][c + 1][d], dp[a][b][c][d]);
if(d + 1 <= c)ndp[a][b][c][d + 1] = max(ndp[a][b][c][d + 1], dp[a][b][c][d]);
if(d >= 1)ndp[a-1][b-1][c-1][d-1] = max(ndp[a-1][b-1][c-1][d-1],dp[a][b][c][d]+1);
}
}
}
}
}else{
for(int a = 0; a <= 20; a++){
for(int b = 0; b <= a; b++){
for(int c = 0; c <= b; c++){
for(int d = 0; d <= c; d++){
ndp[a][b][c][d] = max(ndp[a][b][c][d], dp[a][b][c][d]);
if(s[i] == 'K' && a + 1 <= 20)ndp[a + 1][b][c][d] = max(ndp[a + 1][b][c][d], dp[a][b][c][d]);
if(s[i] == 'U' && b + 1 <= a)ndp[a][b + 1][c][d] = max(ndp[a][b + 1][c][d], dp[a][b][c][d]);
if(s[i] == 'R' && c + 1 <= b)ndp[a][b][c + 1][d] = max(ndp[a][b][c + 1][d], dp[a][b][c][d]);
if(s[i] == 'O' && d + 1 <= c)ndp[a][b][c][d + 1] = max(ndp[a][b][c][d + 1], dp[a][b][c][d]);
if(s[i] == 'I' && d >= 1)ndp[a-1][b-1][c-1][d-1] = max(ndp[a-1][b-1][c-1][d-1],dp[a][b][c][d]+1);
}
}
}
}
}
swap(dp, ndp);
}
int ans = 0;
for(int a = 0; a <= 20; a++){
for(int b = 0; b <= a; b++){
for(int c = 0; c <= b; c++){
for(int d = 0; d <= c; d++){
ans = max(ans, dp[a][b][c][d]);
}
}
}
}
cout << ans << '\n';
}