結果

問題 No.161 制限ジャンケン
コンテスト
ユーザー C
提出日時 2026-10-01 01:47:30
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 5,000 ms
+ 924µs
コード長 1,598 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,964 ms
コンパイル使用メモリ 398,412 KB
実行使用メモリ 9,828 KB
最終ジャッジ日時 2026-10-01 01:47:55
合計ジャッジ時間 9,840 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;

// using mint=modint;

// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;

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

    ll G,C,P;
    string S;
    cin>>G>>C>>P>>S;
    ll N=G+C+P;
    vvll dp(G+1,vector<ll>(C+1,-1));
    dp[0][0]=0;

    for(int i=0;i<N;++i){
        vvll ndp(G+1,vector<ll>(C+1,-1));
        for(int g=0;g<=G;++g){
            for(int c=0;c<=C;++c){
                //押すdpの方は楽
                if(dp[g][c]==-1)continue;

                ll p=i-g-c;

                if(g<G){
                    ll add=0;
                    if(S[i]=='C')add=3;
                    if(S[i]=='G')add=1;
                    ndp[g+1][c]=max(ndp[g+1][c],dp[g][c]+add);
                }

                if(c<C){
                    ll add=0;
                    if(S[i]=='P')add=3;
                    if(S[i]=='C')add=1;
                    ndp[g][c+1]=max(ndp[g][c+1],dp[g][c]+add);
                }

                if(p<P){
                    ll add=0;
                    if(S[i]=='G')add=3;
                    if(S[i]=='P')add=1;
                    ndp[g][c]=max(ndp[g][c],dp[g][c]+add);
                }
            }
        }
        dp=ndp;
    }
    cout<<dp[G][C]<<endl;

}
0