結果

問題 No.161 制限ジャンケン
ユーザー mayoko_mayoko_
提出日時 2015-03-05 23:38:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,772 ms / 5,000 ms
コード長 1,786 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 75,800 KB
実行使用メモリ 30,588 KB
最終ジャッジ日時 2023-08-20 04:21:31
合計ジャッジ時間 6,617 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
10,956 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1,772 ms
30,572 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1,646 ms
30,588 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 59 ms
8,712 KB
testcase_11 AC 54 ms
10,080 KB
testcase_12 AC 24 ms
7,328 KB
testcase_13 AC 941 ms
25,308 KB
testcase_14 AC 104 ms
11,508 KB
testcase_15 AC 297 ms
19,012 KB
testcase_16 AC 64 ms
13,068 KB
testcase_17 AC 48 ms
14,800 KB
testcase_18 AC 33 ms
7,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

int dp[2][334][334][334];

int main(void) {
    int G, C, P;
    cin >> G >> C >> P;
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        int p = i%2;
        for (int j = 0; j <= G; j++) {
            for (int k = 0; k <= C; k++) {
                for (int l = 0; l <= P; l++) {
                    if (s[i] == 'G') {
                        if (j > 0) dp[p][j-1][k][l] = max(dp[p][j-1][k][l], dp[1-p][j][k][l]+1);
                        if (k > 0) dp[p][j][k-1][l] = max(dp[p][j][k-1][l], dp[1-p][j][k][l]);
                        if (l > 0) dp[p][j][k][l-1] = max(dp[p][j][k][l-1], dp[1-p][j][k][l]+3);
                    }
                    if (s[i] == 'C') {
                        if (j > 0) dp[p][j-1][k][l] = max(dp[p][j-1][k][l], dp[1-p][j][k][l]+3);
                        if (k > 0) dp[p][j][k-1][l] = max(dp[p][j][k-1][l], dp[1-p][j][k][l]+1);
                        if (l > 0) dp[p][j][k][l-1] = max(dp[p][j][k][l-1], dp[1-p][j][k][l]);
                    }
                    if (s[i] == 'P') {
                        if (j > 0) dp[p][j-1][k][l] = max(dp[p][j-1][k][l], dp[1-p][j][k][l]);
                        if (k > 0) dp[p][j][k-1][l] = max(dp[p][j][k-1][l], dp[1-p][j][k][l]+3);
                        if (l > 0) dp[p][j][k][l-1] = max(dp[p][j][k][l-1], dp[1-p][j][k][l]+1);
                    }
                }
            }
        }
    }
    cout << max(dp[0][0][0][0], dp[1][0][0][0]) << endl;
    return 0;
}
0