結果

問題 No.161 制限ジャンケン
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-03-05 23:30:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 1,606 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 86,380 KB
実行使用メモリ 110,188 KB
最終ジャッジ日時 2023-08-20 04:20:29
合計ジャッジ時間 2,343 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
109,920 KB
testcase_01 AC 26 ms
109,988 KB
testcase_02 AC 27 ms
110,064 KB
testcase_03 AC 28 ms
109,856 KB
testcase_04 AC 26 ms
109,872 KB
testcase_05 AC 27 ms
110,056 KB
testcase_06 AC 59 ms
110,056 KB
testcase_07 AC 34 ms
109,932 KB
testcase_08 AC 58 ms
109,928 KB
testcase_09 AC 28 ms
109,868 KB
testcase_10 AC 38 ms
109,872 KB
testcase_11 AC 37 ms
110,188 KB
testcase_12 AC 35 ms
110,100 KB
testcase_13 AC 53 ms
109,928 KB
testcase_14 AC 39 ms
109,928 KB
testcase_15 AC 46 ms
110,072 KB
testcase_16 AC 38 ms
109,872 KB
testcase_17 AC 38 ms
109,996 KB
testcase_18 AC 35 ms
109,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

int dp[301][301][301];

int main(){
  int g,c,p;
  cin>>g>>c>>p;
  string s;
  cin>>s;
  clr(dp,-1);
  dp[0][g][c]=0;
  rep(i,1,s.sz+1){
    rep(j,0,301){
      rep(k,0,301){
        if(dp[i-1][j][k]==-1)continue;
        if(s[i-1]=='G'){
          if(j-1>=0)dp[i][j-1][k] = max(dp[i][j-1][k],dp[i-1][j][k]+1);
          if(k-1>=0)dp[i][j][k-1] = max(dp[i][j][k-1],dp[i-1][j][k]);
          dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]+3);
        }
        if(s[i-1]=='C'){
          if(j-1>=0)dp[i][j-1][k] = max(dp[i][j-1][k],dp[i-1][j][k]+3);
          if(k-1>=0)dp[i][j][k-1] = max(dp[i][j][k-1],dp[i-1][j][k]+1);
          dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]);
        }
        if(s[i-1]=='P'){
          if(j-1>=0)dp[i][j-1][k] = max(dp[i][j-1][k],dp[i-1][j][k]);
          if(k-1>=0)dp[i][j][k-1] = max(dp[i][j][k-1],dp[i-1][j][k]+3);
          dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]+1);
        }
      }
    }
  }
  cout << dp[s.sz][0][0] << endl;
  return 0;
}
0