結果

問題 No.161 制限ジャンケン
ユーザー lapilapi
提出日時 2019-08-11 14:37:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,469 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 103,920 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-11 16:39:04
合計ジャッジ時間 2,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A[3];
	for (int i = 0; i < 3; i++) cin >> A[i];

	string S; cin >> S;
	int B[3]; for (int i = 0; i < 3; i++)B[i] = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'G') B[0]++;
		if (S[i] == 'C') B[1]++;
		if (S[i] == 'P') B[2]++;
	}

	int ans = 0;
	int w = min(A[0], B[1]); ans += 3 * w; A[0] -= w; B[1] -= w;
	w = min(A[1], B[2]); ans += 3 * w; A[1] -= w; B[2] -= w;
	w = min(A[2], B[0]); ans += 3 * w; A[2] -= w; B[0] -= w;

	if (B[0] > 0) {
		if (A[0] > 0) {
			int n = min(A[0], B[0]);
			A[0] -= n; B[0] -= n;
			ans += n;
		}
		if (A[1] > 0) {
			int n = min(A[1], B[0]);
			A[0] -= n; B[0] -= n;
		}
	}
	if (B[1] > 0) {
		if (A[1] > 0) {
			int n = min(A[1], B[1]);
			A[1] -= n; B[1] -= n;
			ans += n;
		}
		if (A[2] > 0) {
			int n = min(A[2], B[1]);
			A[2] -= n; B[1] -= n;
		}
	}
	if (B[2] > 0) {
		if (A[2] > 0) {
			int n = min(A[2], B[2]);
			A[0] -= n; B[0] -= n;
			ans += n;
		}
		if (A[0] > 0) {
			int n = min(A[0], B[2]);
			A[0] -= n; B[2] -= n;
		}
	}

	cout << ans << endl;

	return 0;
}
0