結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー aketijyuuzou
提出日時 2025-11-01 16:05:56
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 4,702 bytes
コンパイル時間 7,709 ms
コンパイル使用メモリ 167,488 KB
実行使用メモリ 213,520 KB
最終ジャッジ日時 2025-11-01 16:06:41
合計ジャッジ時間 42,105 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (101 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        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<string> mAiteSet = new HashSet<string>();

    static void Main()
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        List<string> 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, 10);
                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<string>(mAiteSet);

        for (int X = 0; X <= pCharArr.GetUpperBound(0); X++) {
            var RemoveSet = new HashSet<string>();
            foreach (string EachAite in CurrAiteSet) {
                int Syouhai = GetSyouhai(pCharArr[X], EachAite[X]);
                if (Syouhai == -1) {
                    return -1;
                }
                if (Syouhai == 1) {
                    RemoveSet.Add(EachAite);
                }
            }
            // 枝切り
            if (RemoveSet.Count == 0) return -1;

            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;
    }

    ////////////////////////////////////////////////////////////////
    // IEnumerable<string>をcharの2次元配列に設定
    ////////////////////////////////////////////////////////////////
    static char[,] CreateBanArr(IEnumerable<string> 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;
    }
}
0