結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー i_taku
提出日時 2026-01-20 09:37:30
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 681 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 279 ms
コンパイル使用メモリ 82,788 KB
実行使用メモリ 87,428 KB
最終ジャッジ日時 2026-01-20 09:37:35
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, M = map(int, input().split())
S = [input() for _ in range(N)]
fin = set()
H = "GCPG"

def next_h(c):
    return H[H.index(c) + 1]

ans = []
for k in range(M):
    hand_tmp = {'G', 'C', 'P'}
    for i in range(N):
        if i in fin:
            continue
        hand_tmp.discard(next_h(S[i][k]))
    match len(hand_tmp):
        case 0:
            print(-1)
            exit()
        case 1:
            hand = hand_tmp.pop()
        case 2:
            hand = next_h([h for h in H if h not in hand_tmp].pop())
    for i in range(N):
        if S[i][k] == next_h(hand):
            fin.add(i)
    ans.append(hand)
if len(fin) == N:
    print(*ans, sep='')
else:
    print(-1)
0