結果
問題 | No.161 制限ジャンケン |
ユーザー | tottoripaper |
提出日時 | 2015-03-05 23:34:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 46 ms / 5,000 ms |
コード長 | 1,302 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 40,968 KB |
実行使用メモリ | 109,532 KB |
最終ジャッジ日時 | 2023-08-20 04:21:22 |
合計ジャッジ時間 | 1,976 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
109,396 KB |
testcase_01 | AC | 36 ms
109,476 KB |
testcase_02 | AC | 35 ms
109,516 KB |
testcase_03 | AC | 36 ms
109,444 KB |
testcase_04 | AC | 36 ms
109,464 KB |
testcase_05 | AC | 35 ms
109,464 KB |
testcase_06 | AC | 45 ms
109,476 KB |
testcase_07 | AC | 37 ms
109,460 KB |
testcase_08 | AC | 46 ms
109,416 KB |
testcase_09 | AC | 36 ms
109,456 KB |
testcase_10 | AC | 35 ms
109,500 KB |
testcase_11 | AC | 36 ms
109,388 KB |
testcase_12 | AC | 35 ms
109,484 KB |
testcase_13 | AC | 43 ms
109,500 KB |
testcase_14 | AC | 38 ms
109,484 KB |
testcase_15 | AC | 40 ms
109,448 KB |
testcase_16 | AC | 37 ms
109,476 KB |
testcase_17 | AC | 37 ms
109,416 KB |
testcase_18 | AC | 35 ms
109,532 KB |
ソースコード
#include <cstdio> #include <cstring> #include <algorithm> int dp[301][301][301]; char S[310]; // i: p, j: o int battle(char c, char d){ if(c == 'G' && d == 'C' || c == 'C' && d == 'P' || c == 'P' && d == 'G'){ return 3; } if(c == d){return 1;} return 0; } int main(){ int G, C, P; scanf("%d %d %d", &G, &C, &P); scanf("%s", S); int L = strlen(S); std::fill(&dp[0][0][0], &dp[0][0][0]+301*301*301, -1001001001); dp[0][0][0] = 0; for(int i=0;i<L;i++){ for(int j=0;j<=G;j++){ for(int k=0;k<=C;k++){ int l = i - (j + k); if(l < 0 || l > P){continue;} if(j+1 <= G){ dp[i+1][j+1][k] = std::max(dp[i+1][j+1][k], dp[i][j][k] + battle('G', S[i])); } if(k+1 <= C){ dp[i+1][j][k+1] = std::max(dp[i+1][j][k+1], dp[i][j][k] + battle('C', S[i])); } if(l+1 <= P){ dp[i+1][j][k] = std::max(dp[i+1][j][k], dp[i][j][k] + battle('P', S[i])); } } } } int res = 0; for(int j=0;j<=G;j++){ for(int k=0;k<=C;k++){ res = std::max(res, dp[L][j][k]); } } printf("%d\n", res); }