結果
問題 | No.291 黒い文字列 |
ユーザー | latte0119 |
提出日時 | 2015-10-17 00:59:00 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 1,841 bytes |
コンパイル時間 | 2,658 ms |
コンパイル使用メモリ | 151,328 KB |
実行使用メモリ | 6,620 KB |
最終ジャッジ日時 | 2023-09-29 12:34:07 |
合計ジャッジ時間 | 4,142 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,512 KB |
testcase_01 | AC | 6 ms
6,520 KB |
testcase_02 | AC | 6 ms
6,516 KB |
testcase_03 | AC | 6 ms
6,504 KB |
testcase_04 | AC | 5 ms
6,564 KB |
testcase_05 | AC | 5 ms
6,532 KB |
testcase_06 | AC | 4 ms
6,616 KB |
testcase_07 | AC | 5 ms
6,520 KB |
testcase_08 | AC | 6 ms
6,468 KB |
testcase_09 | AC | 5 ms
6,544 KB |
testcase_10 | AC | 12 ms
6,484 KB |
testcase_11 | AC | 10 ms
6,532 KB |
testcase_12 | AC | 9 ms
6,516 KB |
testcase_13 | AC | 5 ms
6,524 KB |
testcase_14 | AC | 8 ms
6,480 KB |
testcase_15 | AC | 6 ms
6,544 KB |
testcase_16 | AC | 19 ms
6,488 KB |
testcase_17 | AC | 23 ms
6,512 KB |
testcase_18 | AC | 21 ms
6,552 KB |
testcase_19 | AC | 30 ms
6,564 KB |
testcase_20 | AC | 33 ms
6,488 KB |
testcase_21 | AC | 29 ms
6,540 KB |
testcase_22 | AC | 39 ms
6,488 KB |
testcase_23 | AC | 46 ms
6,620 KB |
testcase_24 | AC | 34 ms
6,516 KB |
testcase_25 | AC | 30 ms
6,572 KB |
testcase_26 | AC | 29 ms
6,516 KB |
testcase_27 | AC | 29 ms
6,484 KB |
testcase_28 | AC | 29 ms
6,484 KB |
testcase_29 | AC | 29 ms
6,520 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>P; typedef vector<int>VI; #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define maxv(a,b) (a)=max((a),(b)) string kuroi="KUROI"; string s; VI v; int dp[2][25][25][25][25]; int main(){ cin>>s; rep(i,s.size()){ int tmp=-1; rep(j,5)if(kuroi[j]==s[i])tmp=j; if(~tmp)v.pb(tmp); else if(s[i]=='?')v.pb(-1); } bool b=0; memset(dp,-1,sizeof(dp)); dp[0][0][0][0][0]=0; rep(x,v.size()){ rep(u,21)rep(r,21)rep(o,21)rep(i,21){ if(dp[b][u][r][o][i]==-1)continue; maxv(dp[!b][u][r][o][i],dp[b][u][r][o][i]); if(v[x]==0){ maxv(dp[!b][u+1][r][o][i],dp[b][u][r][o][i]); } else if(v[x]==1){ if(u)maxv(dp[!b][u-1][r+1][o][i],dp[b][u][r][o][i]); } else if(v[x]==2){ if(r)maxv(dp[!b][u][r-1][o+1][i],dp[b][u][r][o][i]); } else if(v[x]==3){ if(o)maxv(dp[!b][u][r][o-1][i+1],dp[b][u][r][o][i]); } else if(v[x]==4){ if(i)maxv(dp[!b][u][r][o][i-1],dp[b][u][r][o][i]+1); } else if(v[x]==-1){ maxv(dp[!b][u+1][r][o][i],dp[b][u][r][o][i]); if(u)maxv(dp[!b][u-1][r+1][o][i],dp[b][u][r][o][i]); if(r)maxv(dp[!b][u][r-1][o+1][i],dp[b][u][r][o][i]); if(o)maxv(dp[!b][u][r][o-1][i+1],dp[b][u][r][o][i]); if(i)maxv(dp[!b][u][r][o][i-1],dp[b][u][r][o][i]+1); } dp[b][u][r][o][i]=-1; } b=!b; } int ans=0; rep(u,21)rep(r,21)rep(o,21)rep(i,21)maxv(ans,dp[v.size()&1][u][r][o][i]); printf("%d\n",ans); return 0; }