結果

問題 No.161 制限ジャンケン
ユーザー goodbatongoodbaton
提出日時 2015-09-21 10:23:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,909 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 74,292 KB
実行使用メモリ 119,844 KB
最終ジャッジ日時 2023-08-20 04:42:09
合計ジャッジ時間 2,968 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
119,772 KB
testcase_01 AC 57 ms
119,644 KB
testcase_02 AC 56 ms
119,692 KB
testcase_03 AC 56 ms
119,660 KB
testcase_04 AC 56 ms
119,656 KB
testcase_05 AC 53 ms
119,844 KB
testcase_06 AC 63 ms
119,660 KB
testcase_07 AC 51 ms
119,736 KB
testcase_08 AC 63 ms
119,684 KB
testcase_09 AC 55 ms
119,652 KB
testcase_10 AC 52 ms
119,720 KB
testcase_11 AC 55 ms
119,656 KB
testcase_12 AC 55 ms
119,768 KB
testcase_13 AC 62 ms
119,684 KB
testcase_14 AC 56 ms
119,692 KB
testcase_15 AC 58 ms
119,660 KB
testcase_16 AC 56 ms
119,656 KB
testcase_17 AC 56 ms
119,708 KB
testcase_18 AC 55 ms
119,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000 //(int)1e9
#define LLINF 2000000000000000000 //(ll)2e18
#define PI  3.1415926536

#define SIZE 100000

int dp[310][310][310];


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