結果
問題 | No.161 制限ジャンケン |
ユーザー |
![]() |
提出日時 | 2019-08-11 14:37:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,469 bytes |
コンパイル時間 | 948 ms |
コンパイル使用メモリ | 103,356 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-13 15:18:13 |
合計ジャッジ時間 | 1,785 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#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<<60int 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;}