結果

問題 No.161 制限ジャンケン
ユーザー ty70
提出日時 2015-05-25 12:38:06
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,269 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 110,476 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 04:36:44
合計ジャッジ時間 1,894 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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+1;
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
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0