結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー mtmr_s1
提出日時 2025-11-01 15:23:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,197 bytes
コンパイル時間 3,796 ms
コンパイル使用メモリ 255,428 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2025-11-01 15:23:26
合計ジャッジ時間 4,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;
typedef modint998244353 mint;
//typedef modint1000000007 mint;

void chmin(ll& a, ll b) { a = min(a, b); }
void chmax(ll& a, ll b) { a = max(a, b); }

int N, M;
void dfs(vector<string>& S, vector<int>& R, vector<char>& Hands, int battle){
    if(battle == M && R.size() == 0){
        for(int i = 0; i < Hands.size(); i++){
            cout << Hands[i];
        }
        cout << endl;
        exit(0);
    }
    if(battle == M){
        return;
    }
    for(int k = 0; k < 3; k++){
        vector<int> nextR;
        bool lose = false;
        for(int i = 0; i < R.size(); i++){
            char RivalHand = S[R[i]][battle];
            // G
            if(k == 0){
                if(RivalHand == 'G'){
                    nextR.push_back(R[i]);
                }else if(RivalHand == 'C'){
                    // 勝ち.
                }else if(RivalHand == 'P'){
                    lose = true;
                    break;
                }
            }
            // C
            if(k == 1){
                if(RivalHand == 'C'){
                    nextR.push_back(R[i]);
                }else if(RivalHand == 'P'){
                    // 勝ち.
                }else if(RivalHand == 'G'){
                    lose = true;
                    break;
                }
            }
            // P
            if(k == 2){
                if(RivalHand == 'P'){
                    nextR.push_back(R[i]);
                }else if(RivalHand == 'G'){
                    // 勝ち.
                }else if(RivalHand == 'C'){
                    lose = true;
                    break;
                }
            }

        }
        string HandKind = "GCP";
        if(!lose){
            Hands.push_back(HandKind[k]);
            dfs(S, nextR, Hands, battle + 1);
            Hands.pop_back();
        }
    }
}

int main() {
    cin >> N >> M;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    vector<char> Hands;
    vector<int> R(N);
    for(int i = 0; i < N; i++){
        R[i] = i;
    }
    dfs(S, R, Hands, 0);
    cout << -1 << endl;
}
0