結果

問題 No.161 制限ジャンケン
ユーザー odan3240odan3240
提出日時 2015-12-27 14:39:17
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,517 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 96,400 KB
実行使用メモリ 747,940 KB
最終ジャッジ日時 2023-10-19 11:14:18
合計ジャッジ時間 6,244 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
69,524 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,656 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 MLE -
testcase_07 AC 6 ms
6,272 KB
testcase_08 MLE -
testcase_09 AC 7 ms
6,708 KB
testcase_10 AC 88 ms
70,864 KB
testcase_11 AC 93 ms
79,372 KB
testcase_12 AC 53 ms
42,056 KB
testcase_13 MLE -
testcase_14 AC 136 ms
110,996 KB
testcase_15 AC 290 ms
238,792 KB
testcase_16 AC 110 ms
79,636 KB
testcase_17 AC 113 ms
74,624 KB
testcase_18 AC 65 ms
54,592 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;
}

int G,C,P;
string S;
using Vector=vector<short>;
using Matrix=vector<Vector>;
vector<Matrix> dp[301];
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 main() {
    cin>>G>>C>>P;
    rep(i,301) dp[i]=vector<Matrix>(G+1,Matrix(C+1,Vector(P+1,-1)));
    //rep(i,301) rep(j,dp[i].size()) rep(k,dp[i][j].size()) for(auto &e:dp[i][j][k]) e=-1;
    cin>>S;

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

    return 0;
}
0