結果

問題 No.161 制限ジャンケン
ユーザー ty70ty70
提出日時 2015-05-25 12:32:37
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,297 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 107,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 13:00:00
合計ジャッジ時間 3,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<char,int> CI;

int solve (string s, int G, int C, int P ){
	int res = 0;
	rep (i, s.length() ){
		if (s[i] == 'C' ){
			if (G > 0 ){
				res += 3; G--;
			}else
			if (C > 0 ){
				res += 1; C--;
			}else{
				P--;
			} // end if
		}else
		if (s[i] == 'G' ){
			if (P > 0 ){
				res += 3; P--;
			}else
			if (G > 0 ){
				res += 1; G--;
			}else{
				C--;
			} // end if
		}else{	// if (s[i] == 'P' )
			if (C > 0 ){
				res += 3; C--;
			}else
			if (P > 0 ){
				res += 1; P--;
			}else{
				G--;
			} // end if
		} // end if
	} // end rep

	return res;
}



bool cmp (CI a, CI b ){
	return a.second <= b.second;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int G, C, P; cin >> G >> C >> P;
	string s; cin >> s;
	set<char> g;
	rep (i, s.length() ) g.insert (s[i] );
	set<char>::iterator it = g.begin();
	string order = "";
	for (; it != g.end(); it++ ){
		order += (*it);
	} // end for

	int res = 0;
	do{
		map<char,int> rank_hand; rank_hand.clear();
		rep (i, order.length() ) rank_hand[order[i]] = i;
		vector<CI> curr; curr.clear();
		rep (i, s.length() ){
			char t = s[i];
			int r = rank_hand[s[i]];
			curr.push_back (CI (t, r ) );
		} // end rep

		if (order.length() != 1 )
			sort (ALL (curr ), cmp ); 
		
		string u = "";
		rep (i, s.length() ) u += curr[i].first;
		cerr << u << endl;
		int cur = solve (u, G, C, P );
		res = max (res, cur );
	}while (next_permutation(ALL (order ) ) );

	cout << res << endl;

	return 0;
}
0