結果

問題 No.291 黒い文字列
ユーザー beetbeet
提出日時 2018-12-14 19:06:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,456 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 217,220 KB
実行使用メモリ 222,768 KB
最終ジャッジ日時 2023-10-25 10:11:04
合計ジャッジ時間 12,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 WA -
testcase_25 AC 127 ms
24,140 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 65 ms
14,216 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();
  auto T=[](int a,int b,int c,int d){
           return (((a*22+b)*22)+c)*22+d;
         };
  auto calc=[](int x){
              int d=x%22;x/=22;
              int b=x%22;x/=22;
              int c=x%22;x/=22;
              int a=x%22;x/=22;
              return make_tuple(a,b,c,d);
            };
  vector<map<int, int> > dp(n+1);
  dp[0][T(0,0,0,0)]=0;
  for(int i=0;i<n;i++){
    for(auto p:dp[i]){
      int res=p.second;
      int a,b,c,d;
      tie(a,b,c,d)=calc(p.first);
      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