結果

問題 No.161 制限ジャンケン
ユーザー beet
提出日時 2018-08-09 15:16:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 145 ms / 5,000 ms
コード長 759 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 168,744 KB
実行使用メモリ 292,116 KB
最終ジャッジ日時 2024-09-23 04:35:34
合計ジャッジ時間 5,014 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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
Int dp[333][333][333];
signed main(){
  Int g,c,p;
  string s;
  cin>>g>>c>>p>>s;
  Int n=s.size();
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  for(Int i=0;i<n;i++){
    for(Int x=0;x<=g;x++){
      for(Int y=0;y<=c;y++){
	Int z=i-(x+y);
	if(z<0||i<z) continue;
	chmax(dp[i+1][x+1][y],dp[i][x][y]+(s[i]=='C')*3+(s[i]=='G'));
	chmax(dp[i+1][x][y+1],dp[i][x][y]+(s[i]=='P')*3+(s[i]=='C'));
	chmax(dp[i+1][x][y],dp[i][x][y]+(s[i]=='G')*3+(s[i]=='P'));		
      }
    }
  }
  cout<<dp[n][g][c]<<endl;
  return 0;
}
0