結果
| 問題 |
No.161 制限ジャンケン
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-05 23:34:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 5,000 ms |
| コード長 | 1,302 bytes |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 36,736 KB |
| 実行使用メモリ | 108,116 KB |
| 最終ジャッジ日時 | 2024-11-30 04:25:13 |
| 合計ジャッジ時間 | 1,683 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d %d %d", &G, &C, &P);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%s", S);
| ~~~~~^~~~~~~~~
ソースコード
#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);
}
tottoripaper