結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー 👑 loop0919
提出日時 2026-09-04 22:05:21
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 143 ms / 2,000 ms
+ 94µs
コード長 912 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 273 ms
コンパイル使用メモリ 95,692 KB
実行使用メモリ 113,692 KB
最終ジャッジ日時 2026-09-04 22:05:55
合計ジャッジ時間 5,138 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def win(hands):
    if len(hands) == 1:
        h = hands.pop()

        if h == "G":
            return "P"
        elif h == "C":
            return "G"
        else:
            return "C"
    else:
        l, r = sorted(hands)
        if (l, r) == ("C", "G"):
            return "G"
        elif (l, r) == ("C", "P"):
            return "C"
        else:
            return "P"


N, M = [int(s) for s in input().split()]
S = [[*input()] for _ in range(N)]
remain = {*range(N)}

answers = []


for m in range(M):
    hands = {S[r][m] for r in remain}

    if len(hands) == 3:
        print("-1")
        exit()

    if len(hands) == 0:
        answers.append("G")
        continue

    w = win(hands)
    answers.append(w)

    nremain = set()
    for r in remain:
        if S[r][m] == w:
            nremain.add(r)

    remain = nremain

if len(remain) == 0:
    print(*answers, sep="")
else:
    print(-1)
0