結果

問題 No.161 制限ジャンケン
ユーザー cureskolcureskol
提出日時 2020-04-08 21:05:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 165,500 KB
実行使用メモリ 114,332 KB
最終ジャッジ日時 2023-09-26 11:02:03
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
114,256 KB
testcase_01 AC 38 ms
114,176 KB
testcase_02 AC 38 ms
114,152 KB
testcase_03 AC 38 ms
114,192 KB
testcase_04 AC 38 ms
114,152 KB
testcase_05 AC 38 ms
114,248 KB
testcase_06 AC 48 ms
114,200 KB
testcase_07 AC 39 ms
114,184 KB
testcase_08 AC 47 ms
114,264 KB
testcase_09 AC 39 ms
114,184 KB
testcase_10 AC 40 ms
114,192 KB
testcase_11 AC 40 ms
114,292 KB
testcase_12 AC 39 ms
114,236 KB
testcase_13 AC 45 ms
114,244 KB
testcase_14 AC 40 ms
114,200 KB
testcase_15 AC 41 ms
114,160 KB
testcase_16 AC 40 ms
114,332 KB
testcase_17 AC 39 ms
114,320 KB
testcase_18 AC 39 ms
114,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dp[305][305][305];//dp[i][j][k]:i+1手が終わった時にGのresがj,Cのresがk個
string s;
int f(int idx,int hand){
  int opo;
  if(s[idx]=='G')opo=1;
  if(s[idx]=='C')opo=2;
  if(s[idx]=='P')opo=3;
  if((opo-hand+3)%3==1)return 3;
  if(opo==hand)return 1;
  return 0;
}

signed main(){
  int g,c,p;cin>>g>>c>>p;
  cin>>s;
  for(int i=0;i<305;i++)for(int j=0;j<305;j++)for(int k=0;k<305;k++)dp[i][j][k]=-1e9;
  dp[0][g][c]=0;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<=g;j++){
      for(int k=0;k<=c;k++){
        dp[i+1][j][k]=max({dp[i][j][k]+f(i,3),dp[i][j+1][k]+f(i,1),dp[i][j][k+1]+f(i,2)});
      }
    }
  }
  cout<<dp[s.size()][0][0]<<endl;
}
0