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 HashSet mAiteSet = new HashSet(); static void Main() { var sw = System.Diagnostics.Stopwatch.StartNew(); 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); for (int Y = 0; Y <= UB_Y; Y++) { var sb = new System.Text.StringBuilder(); for (int X = 0; X <= UB_X; X++) { sb.Append(mBanArr[X, Y]); } mAiteSet.Add(sb.ToString()); } var InsRandom = new Random(); char[] CharArr = new char[mM]; while (true) { for (int I = 0; I <= CharArr.GetUpperBound(0); I++) { int Rand = InsRandom.Next(1, 100); if (Rand % 3 == 0) CharArr[I] = 'C'; if (Rand % 3 == 1) CharArr[I] = 'G'; if (Rand % 3 == 2) CharArr[I] = 'P'; } int Result = CheckMethod(CharArr); if (Result == 1) { foreach (char EachChar in CharArr) { Console.Write(EachChar); } Console.WriteLine(); return; } if (sw.ElapsedMilliseconds >= 1900) { // 1.9秒続ける break; } } Console.WriteLine(-1); } static int CheckMethod(char[] pCharArr) { var CurrAiteSet = new HashSet(mAiteSet); for (int X = 0; X <= pCharArr.GetUpperBound(0); X++) { var RemoveSet = new HashSet(); foreach (string EachAite in CurrAiteSet) { int Syouhai = GetSyouhai(pCharArr[X], EachAite[X]); if (Syouhai == -1) { return -1; } if (Syouhai == 1) { RemoveSet.Add(EachAite); } } CurrAiteSet.ExceptWith(RemoveSet); if (CurrAiteSet.Count == 0) 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; } }