結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー nou
提出日時 2026-09-15 11:08:18
言語 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
+ 265µs
コード長 1,796 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,217 ms
コンパイル使用メモリ 176,428 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-15 11:08:27
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:73:13: warning: 'beat' may be used uninitialized [-Wmaybe-uninitialized]
   73 |             if (s[j][i] == beat) won[j] = true;
      |             ^~
main.cpp:17:10: note: 'beat' was declared here
   17 |     char beat;
      |          ^~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    vector<bool> won(n, false);
    bool g, c, p;
    string ans = "";
    char beat;
    for (int i = 0; i < m; i++)
    {
        g = c = p = false;
        for (int j = 0; j < n; j++)
        {
            if (won[j])
                continue;
            if (s[j][i] == 'G')
                g = true;
            if (s[j][i] == 'C')
                c = true;
            if (s[j][i] == 'P')
                p = true;
        }
        if (g + c + p == 1)
        {
            if (g) {
                ans.push_back('P');
                beat = 'G';
            }
            if (c) {
                ans.push_back('G');
                beat = 'C';
            }
            if (p) {
                ans.push_back('C');
                beat = 'P';
            }
        }
        else if (g + c + p == 2)
        {
            if (g && c){
                ans.push_back('G');
                beat = 'C';
            }
            if (c && p) {
                ans.push_back('C');
                beat = 'P';
            }
            if (p && g) {
                ans.push_back('P');
                beat = 'G';
            }
        }
        else if (g + c + p == 3)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            ans.push_back('G');
            beat = 'P';
        }
        for (int j = 0; j < n; j++)
            if (s[j][i] == beat) won[j] = true;
    }
    for (int i = 0; i < n; i++) {
        if (!won[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}
0