結果

問題 No.161 制限ジャンケン
ユーザー mayoko_mayoko_
提出日時 2015-03-05 23:53:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 3,241 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 75,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 04:22:31
合計ジャッジ時間 1,480 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 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;
//}
int dp[2][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++) {
                if ((G-j)+(C-k) > i) continue;
                int l = P-(i-(G-j)-(C-k));
                if (l < 0) break;
                if (s[i] == 'G') {
                    if (j > 0) dp[p][j-1][k] = max(dp[p][j-1][k], dp[1-p][j][k]+1);
                    if (k > 0) dp[p][j][k-1] = max(dp[p][j][k-1], dp[1-p][j][k]);
                    if (l > 0) dp[p][j][k] = max(dp[p][j][k], dp[1-p][j][k]+3);
                }
                if (s[i] == 'C') {
                    if (j > 0) dp[p][j-1][k] = max(dp[p][j-1][k], dp[1-p][j][k]+3);
                    if (k > 0) dp[p][j][k-1] = max(dp[p][j][k-1], dp[1-p][j][k]+1);
                    if (l > 0) dp[p][j][k] = max(dp[p][j][k], dp[1-p][j][k]);
                }
                if (s[i] == 'P') {
                    if (j > 0) dp[p][j-1][k] = max(dp[p][j-1][k], dp[1-p][j][k]);
                    if (k > 0) dp[p][j][k-1] = max(dp[p][j][k-1], dp[1-p][j][k]+3);
                    if (l > 0) dp[p][j][k] = max(dp[p][j][k], dp[1-p][j][k]+1);
                }
            }
        }
    }
    cout << max(dp[0][0][0], dp[1][0][0]) << endl;
    return 0;
}
0