結果

問題 No.161 制限ジャンケン
ユーザー koba-e964koba-e964
提出日時 2015-05-28 16:13:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,450 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 87,756 KB
実行使用メモリ 42,356 KB
最終ジャッジ日時 2023-08-20 04:31:25
合計ジャッジ時間 1,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
42,356 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 17 ms
20,528 KB
testcase_07 AC 5 ms
19,748 KB
testcase_08 AC 19 ms
20,464 KB
testcase_09 AC 2 ms
5,500 KB
testcase_10 AC 3 ms
8,000 KB
testcase_11 AC 4 ms
13,888 KB
testcase_12 AC 3 ms
7,880 KB
testcase_13 AC 14 ms
20,404 KB
testcase_14 AC 5 ms
12,004 KB
testcase_15 AC 8 ms
14,192 KB
testcase_16 AC 5 ms
18,240 KB
testcase_17 AC 5 ms
16,188 KB
testcase_18 AC 4 ms
13,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
const int N = 300;
short dp[N][N][N];

int g,c,p;
string s;

int score(int pos, int ty) {
  char ch = s[pos];
  int q = 0;
  switch(ch) {
  case 'C':
    q = 1; break;
  case 'G':
    q = 0; break;
  case 'P':
    q = 2; break;
  default:
    assert(0);
  }
  switch((ty - q + 3) % 3) {
  case 0:
    return 1;
  case 1:
    return 0;
  default:
    return 3;
  }
}
int main(void){
  cin >> g >> c >> p >> s;
  dp[0][0][0] = 0;
  REP (i, 0, g + 1) {
    REP (j, 0, c + 1) {
      REP (k, 0, p + 1) {
	if (i + j + k == 0) {
	  continue;
	}
	int ma = 0;
	if (i >= 1) {
	  ma = max(ma, dp[i - 1][j][k] + score(i + j + k - 1, 0));
	}
	if (j >= 1) {
	  ma = max(ma, dp[i][j - 1][k] + score(i + j + k - 1, 1));
	}
	if (k >= 1) {
	  ma = max(ma, dp[i][j][k - 1] + score(i + j + k - 1, 2));
	}
	dp[i][j][k] = ma;
      }
    }
  }
  cout << dp[g][c][p] << endl;
}
0