結果

問題 No.161 制限ジャンケン
ユーザー fura
提出日時 2020-04-22 18:15:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 731 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 193,288 KB
最終ジャッジ日時 2025-01-09 22:36:03
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int f(int i,int j){
	if((i+1)%3==j) return 3;
	else if(i==j)  return 1;
	else return 0;
}

string s;
int memo[301][301][301];

int dfs(int g,int c,int p){
	if(g==0 && c==0 && p==0) return 0;

	if(memo[g][c][p]!=-1) return memo[g][c][p];

	int op;
	if(s[s.length()-g-c-p]=='G') op=0;
	if(s[s.length()-g-c-p]=='C') op=1;
	if(s[s.length()-g-c-p]=='P') op=2;

	int res=0;
	if(g>0) res=max(res,dfs(g-1,c,p)+f(0,op));
	if(c>0) res=max(res,dfs(g,c-1,p)+f(1,op));
	if(p>0) res=max(res,dfs(g,c,p-1)+f(2,op));
	return memo[g][c][p]=res;
}

int main(){
	int g,c,p;
	cin>>g>>c>>p>>s;

	memset(memo,-1,sizeof memo);
	cout<<dfs(g,c,p)<<'\n';

	return 0;
}
0