結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー norioc
提出日時 2025-11-03 02:03:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 104,392 KB
最終ジャッジ日時 2025-11-03 02:04:00
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge7 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

def win_hand(hand):
    match hand:
        case 'G': return 'P'
        case 'C': return 'G'
        case 'P': return 'C'

    assert False


def is_win(a, b):
    match a:
        case 'G': return b == 'C'
        case 'C': return b == 'P'
        case 'P': return b == 'G'

    return False


def is_lose(a, b):
    match a:
        case 'G': return b == 'P'
        case 'C': return b == 'G'
        case 'P': return b == 'C'

    return False


N, M = map(int, input().split())
SS = [input() for _ in range(N)]

ans = []
rest = set(range(N))  # 勝利していない相手
for g in zip(*SS):
    hands = set()
    for i, x in enumerate(g):
        if i in rest:
            hands.add(x)

    match len(hands):
        case 0:
            ans.append('G')

        case 1:
            hand = win_hand(list(hands)[0])
            ans.append(hand)
            for i in range(N):
                if is_win(hand, g[i]):
                    rest.discard(i)

        case 2:
            for h in 'GCP':
                if all(not is_lose(h, x) for x in hands):
                    ans.append(h)
                    for i in range(N):
                        if is_win(h, g[i]):
                            rest.discard(i)
                    break

        case 3:
            print(-1)
            exit()

if len(rest) > 0:
    print(-1)
else:
    print(*ans, sep='')
0