結果

問題 No.291 黒い文字列
ユーザー beetbeet
提出日時 2018-12-14 19:03:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,200 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 221,632 KB
実行使用メモリ 174,312 KB
最終ジャッジ日時 2023-10-25 10:10:51
合計ジャッジ時間 11,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 202 ms
28,656 KB
testcase_17 AC 342 ms
38,252 KB
testcase_18 AC 256 ms
32,948 KB
testcase_19 AC 953 ms
83,196 KB
testcase_20 AC 1,246 ms
104,512 KB
testcase_21 AC 53 ms
13,432 KB
testcase_22 AC 1,367 ms
136,416 KB
testcase_23 TLE -
testcase_24 AC 709 ms
80,360 KB
testcase_25 AC 167 ms
30,076 KB
testcase_26 AC 102 ms
20,116 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 10 ms
5,628 KB
testcase_29 AC 62 ms
13,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(min(a+1,20),b,c,d)],res);
      }      
      if(s[i]=='U'||s[i]=='?'){
        if(a) chmax(dp[i+1][T(a-1,min(b+1,20),c,d)],res);
      }     
      if(s[i]=='R'||s[i]=='?'){
        if(b) chmax(dp[i+1][T(a,b-1,min(c+1,20),d)],res);
      }      
      if(s[i]=='O'||s[i]=='?'){
        if(c) chmax(dp[i+1][T(a,b,c-1,min(d+1,20))],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;
}
0