結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー Prala
提出日時 2025-11-01 15:27:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,802 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 79,960 KB
最終ジャッジ日時 2025-11-01 15:27:42
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(5*10**7)
import math
import bisect
import heapq
from collections import deque, defaultdict 
import random
import itertools
#from decimal import Decimal
#from copy import copy, deepcopy
#from sortedcontainers import SortedList

# -------------------------------------------------
pin = sys.stdin.readline
def ST(): return pin().rstrip()
def IN(): return int(pin())
def IM(): return map(int, pin().split())
def IL(): return list(IM())
def SR(n:int)->list: return [pin().rstrip() for _ in range(n)]
def IMatrix(n:int)->list: return [IL() for _ in range(n)]

INF = 2*10**18+1
mod = 998244353
# -------------------------------------------------
#import pypyjit
#pypyjit.set_param("max_unroll_recursion=-1")

N, M = IM()
S = SR(N)

ans = []
win = [0]*N
for j in range(M):
    s = set()
    for i in range(N):
        if win[i]:
            continue
        s.add(S[i][j])
    #print(ans , s)
    if len(s) == 3:
        print(-1)
        exit()
    elif len(s) == 1:
        if "G" in s:
            ans.append("P")
        elif "C" in s:
            ans.append("G")
        else:
            ans.append("C")
        for _ in range(M-j-1):
            ans.append("G")
        print("".join(ans))
        exit()
    else:
        if not 'G' in s:
            ans.append("C")
            for i in range(N):
                if not win[i] and S[i][j] == "P":
                    win[i] = 1
        elif not "C" in s:
            ans.append("P")
            for i in range(N):
                if not win[i] and S[i][j] == "G":
                    win[i] = 1
        else:
            ans.append("G")
            for i in range(N):
                if not win[i] and S[i][j] == "C":
                    win[i] = 1
       
if not all(win):
    print(-1)
else:
    print("".join(ans))
0