結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー Iakatsuki
提出日時 2026-09-04 21:56:19
言語 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  
実行時間 10 ms / 2,000 ms
+ 801µs
コード長 3,497 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,328 ms
コンパイル使用メモリ 367,244 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-09-04 21:56:30
合計ジャッジ時間 6,011 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using lll = __int128;

template <class T> using vc = vector<T>;
using vi = vc<int>;
using vl = vc<ll>;
template <class T> using vv = vc<vc<T>>;
using vvi = vv<int>;
using vvl = vv<ll>;
using vs = vc<string>;
using P = pair<ll, ll>;

const int INF = 1e9;
const ll INF_ll = 1LL << 60;
vl dx = {1, 0, -1, 0}; // vl dx = {1,1,0,-1,-1,-1,0,1};
vl dy = {0, 1, 0, -1}; // vl dx = {0,1,1,1,0,-1,-1,-1};

using ld = long double;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define drep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define drep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define nfor(i, s, n) for (ll i = s; i < (ll)(n); i++)      // i=s,s+1...n-1 ノーマルfor
#define dfor(i, s, n) for (ll i = (s)-1; i >= (ll)(n); i--) // s-1スタートでnまで落ちる
#define fore(c, s) for (auto c : s)                         // for_each

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define YN                                                                                         \
    { cout << "Yes" << endl; }                                                                     \
    else {                                                                                         \
        cout << "No" << endl;                                                                      \
    }
#define dame cout << -1 << endl
#define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end());

bool out_grid(ll i, ll j, ll h, ll w) { // trueならcontinueする
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

ll nc2(ll x) { return x * (x - 1) / 2; }
ll nc3(ll x) { return x * (x - 1) * (x - 2) / 6; }

// const int mint = 998244353;
// const int mint = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vs s(N);
    rep(i, N) { cin >> s[i]; }
    map<char, int> cnt;
    vc<bool> lose(N, false);
    bool ans = false;
    string t;
    rep(i, M) {
        cnt['G'] = 0;
        cnt['C'] = 0;
        cnt['P'] = 0;
        rep(j, N) {
            if (!lose[j]) cnt[s[j][i]]++;
        }
        if (cnt['G'] == 0 && cnt['C'] == 0 && cnt['P'] == 0) {
            ans = true;
            break;
        }
        if ((cnt['G'] != 0 && cnt['C'] != 0 && cnt['P'] != 0)) {
            t += "G";
            continue;
        }
        if ((cnt['G'] == 0 && cnt['C'] == 0)) {
            t += 'C';
            ans = true;
            continue;
        }
        if (cnt['G'] == 0 && cnt['P'] == 0) {
            t += 'G';
            ans = true;
            continue;
        }
        if (cnt['C'] == 0 && cnt['P'] == 0) {
            t += 'P';
            ans = true;
            continue;
        }
        if (cnt['G'] == 0) {
            t += 'C';
            rep(j, N) {
                if (!lose[j] && s[j][i] == 'P') lose[j] = true;
            }
        }
        if (cnt['C'] == 0) {
            t += 'P';
            rep(j, N) {
                if (!lose[j] && s[j][i] == 'G') lose[j] = true;
            }
        }
        if (cnt['P'] == 0) {
            t += 'G';
            rep(j, N) {
                if (!lose[j] && s[j][i] == 'C') lose[j] = true;
            }
        }
    }
    if (ans) {
        cout << t << endl;
    } else {
        cout << -1 << endl;
    }
}
0