using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2 3"); WillReturn.Add("GGG"); WillReturn.Add("CPC"); //GPG } else if (InputPattern == "Input2") { WillReturn.Add("4 3"); WillReturn.Add("PGC"); WillReturn.Add("PCP"); WillReturn.Add("PPG"); WillReturn.Add("GGP"); //-1 } else if (InputPattern == "Input3") { WillReturn.Add("4 5"); WillReturn.Add("PGCPC"); WillReturn.Add("PPGGP"); WillReturn.Add("CPGPC"); WillReturn.Add("CGCCP"); //CPPCP } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static long[] GetSplitArr(string pStr) { return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray(); } static long mN; static long mM; static char[,] mBanArr; static int UB_X; static int UB_Y; static void Main() { List InputList = GetInputList(); long[] wkArr = GetSplitArr(InputList[0]); mN = wkArr[0]; mM = wkArr[1]; mBanArr = CreateBanArr(InputList.Skip(1)); UB_X = mBanArr.GetUpperBound(0); UB_Y = mBanArr.GetUpperBound(1); var Stk = new Stack(); JyoutaiDef WillPush; WillPush.Path = ""; Stk.Push(WillPush); while (Stk.Count > 0) { JyoutaiDef Popped = Stk.Pop(); int Result = CheckMethod(Popped.Path); if (Result == 1) { Console.WriteLine(Popped.Path.PadRight((int)mM, 'P')); return; } if (Popped.Path.Length == 11) { continue; } if (Popped.Path.Length < mM) { WillPush.Path = Popped.Path + 'C'; Stk.Push(WillPush); WillPush.Path = Popped.Path + 'G'; Stk.Push(WillPush); WillPush.Path = Popped.Path + 'P'; Stk.Push(WillPush); } } Console.WriteLine(-1); } static int CheckMethod(string pPath) { var WinIndSet = new HashSet(); for (int X = 0; X <= pPath.Length - 1; X++) { for (int Y = 0; Y <= UB_Y; Y++) { if (WinIndSet.Contains(Y)) continue; int Syouhai = GetSyouhai(pPath[X], mBanArr[X, Y]); if (Syouhai == -1) { return -1; } if (Syouhai == 1) { WinIndSet.Add(Y); } } if (WinIndSet.Count == mN) return 1; } return 0; } static int GetSyouhai(char pIwai, char pAite) { if (pIwai == 'C' && pAite == 'G') return -1; if (pIwai == 'G' && pAite == 'P') return -1; if (pIwai == 'P' && pAite == 'C') return -1; if (pIwai == 'C' && pAite == 'P') return +1; if (pIwai == 'G' && pAite == 'C') return +1; if (pIwai == 'P' && pAite == 'G') return +1; return 0; } struct JyoutaiDef { internal string Path; } //////////////////////////////////////////////////////////////// // IEnumerableをcharの2次元配列に設定 //////////////////////////////////////////////////////////////// static char[,] CreateBanArr(IEnumerable pStrEnum) { var StrList = pStrEnum.ToList(); if (StrList.Count == 0) { return new char[0, 0]; } int UB_X = StrList[0].Length - 1; int UB_Y = StrList.Count - 1; char[,] WillReturn = new char[UB_X + 1, UB_Y + 1]; for (int Y = 0; Y <= UB_Y; Y++) { for (int X = 0; X <= UB_X; X++) { WillReturn[X, Y] = StrList[Y][X]; } } return WillReturn; } }