結果

問題 No.161 制限ジャンケン
ユーザー furafura
提出日時 2020-04-22 18:15:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 731 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 196,028 KB
実行使用メモリ 110,208 KB
最終ジャッジ日時 2024-04-20 03:24:48
合計ジャッジ時間 3,679 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
109,952 KB
testcase_01 AC 47 ms
110,080 KB
testcase_02 AC 34 ms
110,032 KB
testcase_03 AC 30 ms
110,080 KB
testcase_04 AC 31 ms
110,144 KB
testcase_05 AC 31 ms
110,020 KB
testcase_06 AC 54 ms
110,208 KB
testcase_07 AC 31 ms
110,000 KB
testcase_08 AC 62 ms
110,144 KB
testcase_09 AC 30 ms
109,948 KB
testcase_10 AC 32 ms
109,948 KB
testcase_11 AC 32 ms
109,952 KB
testcase_12 AC 31 ms
110,160 KB
testcase_13 AC 58 ms
110,080 KB
testcase_14 AC 45 ms
110,080 KB
testcase_15 AC 36 ms
110,080 KB
testcase_16 AC 33 ms
110,080 KB
testcase_17 AC 41 ms
110,080 KB
testcase_18 AC 34 ms
110,008 KB
権限があれば一括ダウンロードができます

ソースコード

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