結果

問題 No.161 制限ジャンケン
ユーザー IJMP320
提出日時 2015-03-05 23:53:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,008 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 162,320 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 04:26:29
合計ジャッジ時間 2,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;
const int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};
struct P{int x;int y;P(int X=0,int Y=0){x=X;y=Y;}};

int G,C,P;
string s;

int main() {
	char buf[301];
	cin >> G >> C >> P >> buf;
	s = buf;

	int ans = 0;
	sort(s.begin(), s.end());   // C G P
	rep(i,s.size()) {
		if(s[i] == 'C') {
			if(G > 0) {
				G--;
				ans += 3;
				s[i] = '#';
			}
		}
		else if(s[i] == 'G') {
			if(P > 0) {
				P--;
				ans += 3;
				s[i] = '#';
			}
		}
		else {
			if(C > 0) {
				C--;
				ans += 3;
				s[i] = '#';
			}
		}
	}

	rep(i,s.size()) {
		if(s[i] == '#') continue;
		if(s[i] == 'C') {
			if(C > 0) {
				C--;
				ans += 1;
				s[i] = '#';
			}
		}
		else if(s[i] == 'G') {
			if(G > 0) {
				G--;
				ans += 1;
				s[i] = '#';
			}
		}
		else {
			if(P > 0) {
				P--;
				ans += 1;
				s[i] = '#';
			}
		}
	}

	cout << ans << endl;
	return 0;
}
0