結果

問題 No.161 制限ジャンケン
ユーザー odan3240odan3240
提出日時 2015-12-27 18:38:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,686 ms / 5,000 ms
コード長 2,127 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 87,960 KB
実行使用メモリ 28,472 KB
最終ジャッジ日時 2023-08-20 04:47:31
合計ジャッジ時間 13,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
10,984 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3,644 ms
28,436 KB
testcase_07 AC 3 ms
4,412 KB
testcase_08 AC 3,686 ms
28,472 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 136 ms
8,212 KB
testcase_11 AC 116 ms
9,704 KB
testcase_12 AC 53 ms
7,304 KB
testcase_13 AC 2,283 ms
23,636 KB
testcase_14 AC 246 ms
11,036 KB
testcase_15 AC 769 ms
17,880 KB
testcase_16 AC 136 ms
12,536 KB
testcase_17 AC 87 ms
14,144 KB
testcase_18 AC 75 ms
7,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef long long ll;

int calc(char c1,char c2) {
    if(c1==c2) return 1;
    if(c1=='G'&&c2=='P') return 3;
    if(c1=='P'&&c2=='C') return 3;
    if(c1=='C'&&c2=='G') return 3;
    return 0;
}

template<class T>
bool chmax(T &a, const T &b) {
    if(a<b) {
        a=b;
        return true;
    }
    return false;
}
int G,C,P;
string S;
/*
int dfs(int idx,int g,int c,int p) {
    if(idx==S.size()) return 0;
    int ret = 0;
    if(dp[idx][g][c][p]!=-1) return dp[idx][g][c][p];
    if(g!=0) ret = max(dfs(idx+1,g-1,c,p)+calc(S[idx],'G'), ret);
    if(c!=0) ret = max(dfs(idx+1,g,c-1,p)+calc(S[idx],'C'), ret);
    if(p!=0) ret = max(dfs(idx+1,g,c,p-1)+calc(S[idx],'P'), ret);

    return dp[idx][g][c][p]=ret;
}
*/

int dp[2][301][301][301];
int main() {
    cin>>G>>C>>P;
    cin>>S;
    rep(i,S.size()) {
        rep(x,G+1) rep(y,C+1) rep(z,P+1) {
            int g=x;
            int c=y;
            int p=z;
            chmax(dp[(i+1)&1][g+1][c][p],dp[(i&1)][g][c][p]+calc(S[i],'G'));
            chmax(dp[(i+1)&1][g][c+1][p],dp[(i&1)][g][c][p]+calc(S[i],'C'));
            chmax(dp[(i+1)&1][g][c][p+1],dp[(i&1)][g][c][p]+calc(S[i],'P'));
            
            //if(g!=0) chmax(dp[(i&1)][g][c][p],dp[(i+1)&1][g-1][c][p]+calc(S[i],'G'));
            //if(c!=0) chmax(dp[(i&1)][g][c][p],dp[(i+1)&1][g][c-1][p]+calc(S[i],'C'));
            //if(p!=0) chmax(dp[(i&1)][g][c][p],dp[(i+1)&1][g][c][p-1]+calc(S[i],'P'));
        }
    }
    cout<<dp[S.size()&1][G][C][P]<<endl;

    //cout<<dfs(0,G,C,P)<<endl;

    return 0;
}
0