結果
問題 | No.161 制限ジャンケン |
ユーザー |
![]() |
提出日時 | 2015-03-05 23:38:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,407 ms / 5,000 ms |
コード長 | 1,786 bytes |
コンパイル時間 | 641 ms |
コンパイル使用メモリ | 76,512 KB |
実行使用メモリ | 30,720 KB |
最終ジャッジ日時 | 2024-11-30 04:25:21 |
合計ジャッジ時間 | 5,366 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#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; }